1

我有一个 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>());

这应该解决新的代理类。

4

2 回答 2

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 参数的名称。我没有在编译器中运行它,所以如果这对你有用,请告诉我。

亲切的问候,马尔维恩。

于 2013-03-21T07:28:13.283 回答
0

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

container.Register(
    Component.For<IBatchDataService>().
        ImplementedBy<BatchDataServiceClient>(),
    Component.For<IBatchDataService().
        AsWcfClient(WCFEndpoint.FromConfiguration("Internal.IBatchDataService")).
        LifestyleTransient());
于 2013-03-21T13:26:28.333 回答