You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB
C#

11 months ago
using Autofac;
using Autofac.Extras.DynamicProxy;
using System.Reflection;
namespace DS.Module.AutofacModule;
/// <summary>
///
/// </summary>
11 months ago
public class AutofacModuleRegister : Autofac.Module
{
/// <summary>
/// 将模块服务添加到依赖注入服务容器中
/// </summary>
/// <param name="services">依赖注入服务容器</param>
/// <returns></returns>
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 带有接口层的服务注入
}
}