C# 4.0 温莎城堡按惯例注册定制生活方式

C# 4.0 温莎城堡按惯例注册定制生活方式,c#-4.0,castle-windsor,C# 4.0,Castle Windsor,有了温莎城堡,就可以按照惯例进行注册,并设置一种定制的生活方式,如 或者您必须注册每个组件吗?container.Register( container.Register( Classes.FromThisAssembly() .BasedOn<ISomething>() .Configure(c => c.LifestyleCustom<YourLifestyle>()) ); 类。FromThisAssembly() .Based

有了温莎城堡,就可以按照惯例进行注册,并设置一种定制的生活方式,如 或者您必须注册每个组件吗?

container.Register(
container.Register(
   Classes.FromThisAssembly()
      .BasedOn<ISomething>()
      .Configure(c => c.LifestyleCustom<YourLifestyle>())
);
类。FromThisAssembly() .BasedOn() .Configure(c=>c.LifestyleCustom()) );
或者,如果您正在使用Windsor 3.1或从不使用:

container.Register(
   Classes.FromThisAssembly()
      .BasedOn<ISomething>()
      .LifestyleCustom<YourLifestyle>()
);
container.Register(
类。FromThisAssembly()
.BasedOn()
.生活方式习惯
);

对于Mauricio的生活方式扩展(您链接的那一个),这对我有用:

using Castle.MicroKernel.Lifestyle;

/// ...

container.Register(AllTypes.FromThisAssembly()
       .Where(Component.IsInSameNamespaceAs<MyNameSpace.SomeService>())
       .WithService.DefaultInterfaces().LifestyleScoped<HybridPerWebRequestPerThreadScopeAccessor>());
使用Castle.MicroKernel.lifety;
/// ...
container.Register(AllTypes.fromthissassembly())
.Where(Component.IsInSameNamespaceAs())
.WithService.DefaultInterfaces().LifeStyleScope());

Ok,我已经找到了如何为每个组件配置生活方式的方法,但是如果我想将生活方式配置集中到一个贡献组件(我将从调用应用程序中设置该组件),该怎么办