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.

44 lines
1.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Autofac;
using Autofac.Extras.DynamicProxy;
using System.Reflection;
namespace DS.Module.AutofacModule;
/// <summary>
///
/// </summary>
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()
//.InstancePerLifetimeScope()
; //引用Autofac.Extras.DynamicProxy
//.InterceptedBy(cacheType.ToArray());//允许将拦截器服务的列表分配给注册。
#endregion 带有接口层的服务注入
}
}