[英]how to resolve a proxy class in Castle Windsor
I have a WCF service that I'm trying to resolve using Castle Windsor. 我有一个WCF服务,我正在尝试使用Castle Windsor解决。 The registration used to look like this:
注册过去看起来像这样:
container.Register(Component.For<IBatchDataService>()
.AsWcfClient(WCFEndpoint
.FromConfiguration("Internal.IBatchDataService"))
.LifestyeTransient())
Now I've created a proxy that lives in process. 现在,我创建了一个可以运行的代理。 It exposes the same interface (IBatchDataService) and takes a reference to the WCF service as a constructor argument.
它公开相同的接口(IBatchDataService),并将对WCF服务的引用作为构造函数参数。 How do I set up this up in Windsor so that any other classes get resolved to use the proxy class but the proxy class resolves to the WCF service.
我如何在Windsor中进行设置,以便使其他任何类都解析为使用代理类,但代理类解析为WCF服务。 I have this right now:
我现在有这个:
container.Register(Component.For<IBatchDataService>()
.ImplementedBy<BatchDataServiceClient>());
which should resolve the new proxy class. 这应该解析新的代理类。
Try this: 尝试这个:
container.Register(
Component.For<IBatchDataService>().AsWcfClient(WCFEndpoint.FromConfiguration("Internal.IBatchDataService")).LifestyeTransient().Named("wcfBatchDataService"),
Component.For<IBatchDataService>().ImplementedBy<BatchDataServiceClient>().AsDefault().DependsOn(
Dependency.OnComponent("constructorParameterName", "wcfBatchDataService")
)
Where constructorParameterName is the name of the IBatchDataService parameter on your constructor. 其中ConstructorParameterName是构造函数上IBatchDataService参数的名称。 I've not run it in a compiler so please let me know if this works for you.
我尚未在编译器中运行它,所以请告诉我这是否适合您。
Kind regards, Marwijn. 亲切的问候,Marwijn。
It is simply a decorator pattern. 它只是一个装饰器模式。 Windsor support's it OOTB:
温莎支持的OOTB:
container.Register(
Component.For<IBatchDataService>().
ImplementedBy<BatchDataServiceClient>(),
Component.For<IBatchDataService().
AsWcfClient(WCFEndpoint.FromConfiguration("Internal.IBatchDataService")).
LifestyleTransient());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.