使用Castle Windsor可以使用Registration By Convention并设置自定义生活方式 Hybrid Life Styles或者你必须注册每个组件吗?
答案 0 :(得分:0)
container.Register(
Classes.FromThisAssembly()
.BasedOn<ISomething>()
.Configure(c => c.LifestyleCustom<YourLifestyle>())
);
或者如果您使用的是Windsor 3.1或从不使用:
container.Register(
Classes.FromThisAssembly()
.BasedOn<ISomething>()
.LifestyleCustom<YourLifestyle>()
);
答案 1 :(得分:0)
对于Mauricio的生活方式扩展(你链接的那个),这对我有用:
using Castle.MicroKernel.Lifestyle;
/// ...
container.Register(AllTypes.FromThisAssembly()
.Where(Component.IsInSameNamespaceAs<MyNameSpace.SomeService>())
.WithService.DefaultInterfaces().LifestyleScoped<HybridPerWebRequestPerThreadScopeAccessor>());