using Autofac;
using Autofac.Extras.DynamicProxy;
using System.Reflection;
namespace DS.Module.AutofacModule;
///
///
///
public class AutofacModuleRegister : Autofac.Module
{
///
/// 将模块服务添加到依赖注入服务容器中
///
/// 依赖注入服务容器
///
protected override void Load(ContainerBuilder builder)
{
var basePath = AppContext.BaseDirectory;
#region 带有接口层的服务注入
var servicesDllFile = Path.Combine(basePath, "DS.WMS.Core.dll");
if (!(File.Exists(servicesDllFile)))
{
var msg = "Service.dll 丢失,因为项目解耦了,所以需要先F6编译,再F5运行,请检查 bin 文件夹,并拷贝。";
throw new Exception(msg);
}
// 获取 Service.dll 程序集服务,并注册
var assemblysServices = Assembly.LoadFrom(servicesDllFile);
builder.RegisterAssemblyTypes(assemblysServices)
.AsImplementedInterfaces()
.InstancePerDependency()
.PropertiesAutowired()
.EnableInterfaceInterceptors(); //引用Autofac.Extras.DynamicProxy
//.InterceptedBy(cacheType.ToArray());//允许将拦截器服务的列表分配给注册。
#endregion 带有接口层的服务注入
}
}