How can I register all my services with castle win

2019-07-06 02:22发布

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条回答
Emotional °昔
2楼-- · 2019-07-06 02:52

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());
查看更多
登录 后发表回答