Product_Wms/WcsMain/StartAction/AutofacModule.cs
icewint 03c600bc70 1、修改文件结构
2、删除不使用的 using
2024-11-15 11:38:01 +08:00

32 lines
1007 B
C#

using Autofac;
using System.Reflection;
using WcsMain.Constant.WcsAttribute.AutoFacAttribute;
namespace WcsMain.StartAction;
public class AutofacModule : Autofac.Module
{
/*
* 此处为依赖注入,注入的是单例模式
*/
protected override void Load(ContainerBuilder builder)
{
var assembly = Assembly.GetExecutingAssembly();
// 注册 Service
builder.RegisterAssemblyTypes(assembly)
.Where(w => w.GetCustomAttribute(typeof(ServiceAttribute)) != default)
.SingleInstance();
// 注册 Component
builder.RegisterAssemblyTypes(assembly)
.Where(w => w.GetCustomAttribute(typeof(ComponentAttribute)) != default)
.SingleInstance();
// 添加属性注入 --- 一般不建议使用
builder.RegisterAssemblyTypes(assembly)
.Where(w => w.GetCustomAttribute(typeof(AutowiredAttribute)) != default)
.PropertiesAutowired(new AutowiredSelector());
}
}