Windsor Castle 3.0使用IContributeComponentModelConstruction将生活方式设置为WcfPerOperation

时间:2013-12-05 05:43:01

标签: wcf castle-windsor windsor-3.0 windsor-facilities

在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实现同样的目标?

1 个答案:

答案 0 :(得分:1)

我通过重写ProcessModel方法解决了这个问题,如下所示:

public void ProcessModel(IKernel kernel, ComponentModel model)
    {
            model.LifestyleType = LifestyleType.Scoped;
            model.ExtendedProperties[Constants.ScopeAccessorType] = typeof(WcfOperationScopeAccessor);
    }