How can I register all my services with castle windsor wcf facility

谁都会走 提交于 2019-12-23 18:18:49

问题


Basicly I can register one service like this.

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

But I could not figure out how to register all my services with similar configuration.

the thing I was hoping to run is this...

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()
        );

How can I register all services as wcf client?


回答1:


Using Windsor 3.0, you just need to use Types instead of AllTypes so that it registers the service interface and generates a client side dynamic proxy for you like so:

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());


来源:https://stackoverflow.com/questions/8489140/how-can-i-register-all-my-services-with-castle-windsor-wcf-facility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!