builder.RegisterAssemblyTypes(typeof(IProductService).Assembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();

 备注:

a. 如果 IProductService 有 2 个实现类,那么运行时用到 IProductService 会抛出异常。

b. 如果 IProductService 有 2 个实现类,ProductService1 和 ProductService2(抽象类),那么 Autofac 自动采用 ProductService1 作为实现类。

 

2. 未完待续...

谢谢浏览!

相关文章: