wcs_server_kate_suzhou/WcsMain/StartAction/AutofacModule.cs

32 lines
998 B
C#
Raw Normal View History

2024-05-14 16:30:56 +08:00
using Autofac;
using System.Reflection;
using WcsMain.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());
}
}