0

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

4

1 回答 1

1

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

public void ProcessModel(IKernel kernel, ComponentModel model)
    {
            model.LifestyleType = LifestyleType.Scoped;
            model.ExtendedProperties[Constants.ScopeAccessorType] = typeof(WcfOperationScopeAccessor);
    }
于 2014-10-13T13:46:58.530 回答