SOF*_*ser 2 c# dependency-injection castle-windsor autofac
我在温莎城堡注册了这个.什么是AutoFac中的替代代码?
//Transient
context.IocManager.IocContainer.Register(
Classes.FromAssembly(context.Assembly)
.IncludeNonPublicTypes()
.BasedOn<ITransientDependency>()
.WithService.Self()
.WithService.DefaultInterfaces()
.LifestyleTransient()
);
Run Code Online (Sandbox Code Playgroud)
试试这个 :
builder.RegisterAssemblyTypes(context.Assembly)
.Where(t => t.GetInterfaces().Any(i => i == typeof(ITransientDependency)))
.AsSelf()
.As(t => t.GetInterfaces().Where(i => t.Name.Contains(i.Name.Substring(1))));
Run Code Online (Sandbox Code Playgroud)
您不必使用该.InstancePerDependency()方法来指定您的注册将是暂时的,因为这是Autofac中的默认设置
| 归档时间: |
|
| 查看次数: |
242 次 |
| 最近记录: |