【问题标题】:how to resolve a proxy class in Castle Windsor如何解决温莎城堡中的代理类
【发布时间】:2013-03-20 23:08:54
【问题描述】:

我有一个 WCF 服务,我正在尝试使用 Castle Windsor 来解决它。以前的注册是这样的:

container.Register(Component.For<IBatchDataService>()
.AsWcfClient(WCFEndpoint
.FromConfiguration("Internal.IBatchDataService"))
.LifestyeTransient())

现在我创建了一个进程中的代理。它公开相同的接口 (IBatchDataService) 并将 WCF 服务的引用作为构造函数参数。如何在 Windsor 中进行设置,以便将任何其他类解析为使用代理类,但代理类解析为 WCF 服务。我现在有这个:

container.Register(Component.For<IBatchDataService>()
.ImplementedBy<BatchDataServiceClient>());

应该解析新的代​​理类。

【问题讨论】:

    标签: c# wcf castle-windsor wcffacility


    【解决方案1】:

    试试这个:

    container.Register(
        Component.For<IBatchDataService>().AsWcfClient(WCFEndpoint.FromConfiguration("Internal.IBatchDataService")).LifestyeTransient().Named("wcfBatchDataService"),
        Component.For<IBatchDataService>().ImplementedBy<BatchDataServiceClient>().AsDefault().DependsOn(
            Dependency.OnComponent("constructorParameterName", "wcfBatchDataService")
    )
    

    constructorParameterName 是构造函数上 IBatchDataService 参数的名称。 我没有在编译器中运行它,所以如果这对你有用,请告诉我。

    亲切的问候, 马尔维恩。

    【讨论】:

      【解决方案2】:

      它只是一个装饰器模式。温莎支持 OOTB:

      container.Register(
          Component.For<IBatchDataService>().
              ImplementedBy<BatchDataServiceClient>(),
          Component.For<IBatchDataService().
              AsWcfClient(WCFEndpoint.FromConfiguration("Internal.IBatchDataService")).
              LifestyleTransient());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多