gpt4 book ai didi

dependency-injection - 如何使用 caSTLe windsor wcf 设施注册我的所有服务

转载 作者:行者123 更新时间:2023-12-04 08:21:31 24 4
gpt4 key购买 nike

基本上我可以像这样注册一个服务。

Container.Register(Component.For<IMyService>()
.AsWcfClient(new DefaultClientModel() {
Endpoint = WcfEndpoint
.BoundTo(new NetNamedPipeBinding())
.At("net.pipe://localhost/MyService") })
.LifeStyle.PerWebRequest);

但我不知道如何用类似的配置注册我的所有服务。

我希望运行的是这个...

Container.Register(
AllTypes.FromAssemblyNamed("My.Server.MyContracts")
.Pick().If(x => x.Name.EndsWith("Service"))
.Configure(configurer => configurer.Named(configurer.Implementation.Name)
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint.BoundTo(new NetNamedPipeBinding())
.At(string.Format("net.pipe://localhost/{0}", configurer.Named(configurer.Implementation.Name)).Substring(1))
}))
.LifestylePerWebRequest()
);

如何将所有服务注册为 wcf 客户端?

最佳答案

使用 Windsor 3.0,你只需要使用 Types 而不是 AllTypes 以便它注册服务接口(interface)并为你生成客户端动态代理,如下所示:

Container
.Register(
Types
.FromAssemblyNamed("My.Server.MyContracts")
.Pick()
.If(x => x.Name.EndsWith("Service"))
.Configure(
configurer => configurer.Named(configurer.Implementation.Name)
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint
.BoundTo(new NetNamedPipeBinding())
.At(string.Format(
"net.pipe://localhost/{0}",
configurer.Name.Substring(1)))
}))
.LifestylePerWebRequest());

关于dependency-injection - 如何使用 caSTLe windsor wcf 设施注册我的所有服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com