在Windsor 2.1中,当代码在wcf上下文中执行时,我有以下代码将所有服务的生活方式改为PerWcfOperation:
container.Kernel.ComponentModelBuilder.AddContributor(
new CustomLifestyleLevelingContributeComponentModelConstruction(typeof (PerWcfOperationLifestyle))
其中CustomLifestyleLevelingContributeComponentModelConstruction是:
public class CustomLifestyleLevelingContributeComponentModelConstruction : IContributeComponentModelConstruction
{
private readonly Type customLifestyleType;
private readonly List<LifestyleType> ignoredLifetyles;
public CustomLifestyleLevelingContributeComponentModelConstruction(Type customLifestyleType)
{
this.customLifestyleType = customLifestyleType;
}
public void ProcessModel(IKernel kernel, ComponentModel model)
{
model.LifestyleType = LifestyleType.Custom;
model.CustomLifestyle = customLifestyleType;
}
}
我的问题是类 PerWcfOperationLifestyle已从Windsor 3.0中删除。有谁能告诉我如何用Windsor 3.x实现同样的目标?
答案 0 :(得分:1)
我通过重写ProcessModel方法解决了这个问题,如下所示:
public void ProcessModel(IKernel kernel, ComponentModel model)
{
model.LifestyleType = LifestyleType.Scoped;
model.ExtendedProperties[Constants.ScopeAccessorType] = typeof(WcfOperationScopeAccessor);
}