【问题标题】:Windsor Castle 3.0 use IContributeComponentModelConstruction to set lifestyle to WcfPerOperationWindsor Castle 3.0 使用 IContributeComponentModelConstruction 将生活方式设置为 WcfPerOperation
【发布时间】:2013-12-05 05:43:00
【问题描述】:

在 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;
    }
}

我的问题是 class PerWcfOperationLifestyle 已从 Windsor 3.0 中删除。谁能告诉我如何使用 Windsor 3.x 实现相同的目标?

【问题讨论】:

  • 你有没有想过这个问题?我正在尝试做同样的事情。
  • 是的,我刚刚为那些需要做同样事情的人添加了一个答案:)

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 2015-10-03
    • 1970-01-01
    • 2012-02-02
    相关资源
    最近更新 更多