2011-12-13 43 views
3

基本上我可以注册一个这样的服务。如何注册我的所有服务与城堡温莎wcf设施

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客户端?

回答

4

使用温莎3.0,您只需使用类型代替AllTypes,以便它注册的服务接口和你那么生成的客户端动态代理:

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