2013-03-20 56 views
1

我有一个WCF服务,我试图使用温莎城堡解决。看惯了这样的登记:如何解决温莎城堡代理类

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

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

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

应该解决新的代理类。

回答

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的名称。 我没有在编译器中运行它,所以请让我知道这是否适用于您。

亲切的问候, Marwijn。

0

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

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