2011-12-13 59 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());