Ani*_*aha 6 c# dependency-injection asp.net-core-mvc asp.net-core
在统一中,我可以使用这种方式从程序集中注册所有类型的接口.
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterTypes(
AllClasses.FromLoadedAssemblies().
Where(
type =>
typeof (IRunAtInit).IsAssignableFrom(type),
WithMappings.FromAllInterfaces,
WithName.TypeName);
}
Run Code Online (Sandbox Code Playgroud)
是否有可能使用自己的默认服务容器以这种方式实现.net核心?
尝试使用Scrutor扩展:https : //github.com/khellang/Scrutor
services.Scan(scan => scan
.FromAssemblyOf<IRunAtInit>()
.AddClasses(classes => classes.AssignableTo<IRunAtInit>())
.AsImplementedInterfaces()
.WithTransientLifetime());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
733 次 |
| 最近记录: |