2010-04-23 47 views
1

目前,我们使用WCF集成工具在Windsor容器中使用WCF代理的编程注册。例如:使用WCF集成工具WCF代理的Castle Windsor XML配置

container.Register(
    Component.For<CalculatorSoap>() 
     .Named("calculatorSoap") 
     .LifeStyle.Transient 
     .ActAs(new DefaultClientModel 
     { 
     Endpoint = WcfEndpoint.FromConfiguration("CalculatorSoap").LogMessages() 
     } 
    ) 
    ); 

有没有办法通过Windsor XML配置文件来做同样的事情。我无法在Google上找到此示例。

在此先感谢

+0

为什么你想把它放在.config?代码是推荐的方式 – 2010-04-23 10:06:50

+0

因为我们想要改变基于环境的实现:dev env的内存中实现和生产env的WCF代理。恕我直言,配置是最合适的方式。目前,我们使用一种解决方法 - 自定义WindsorInstaller来执行if-else逻辑。 – 2010-04-23 10:13:40

+0

我认为'IWindsorInstaller'方法更好。将环境名称移至.config,而不是组件。 – 2010-04-23 10:18:52

回答

2

城堡WCF集成工具库(http://github.com/castleproject/Castle.Facilities.Wcf)现在包含从温莎配置文件WCF客户端注册的样本:

<?xml version='1.0' encoding='utf-8' ?> 
<configuration> 
<facilities> 
    <facility id='wcf' 
       type='Castle.Facilities.WcfIntegration.WcfFacility, 
        Castle.Facilities.WcfIntegration' /> 
</facilities> 

<components> 
    <component id='calculatorSoap' 
       type='Demo.CalculatorSoap, Demo.UnitTests' 
       wcfEndpointConfiguration='CalculatorSoap'> 
    </component> 
</components> 
</configuration> 

这就是我一直在寻找。 谢谢你的帮助。

注意:注意生活方式。在一般情况下,WCF代理必须具有临时生活方式才能在对象释放时关闭。虽然默许温莎的生活方式是单身,在这种情况下,WCF代理将关闭容器处置。

Regards,Andrej

1

使用IWindsorInstaller和做通过代码注册是推荐的方式。配置用于配置(和传统方案)。

我会为此创建两个安装程序,并基于编译标志使用一个或另一个;

var installer = 
#if DEBUG 
new TestingServiceInstaller(); 
#elseif 
new ProductionServiceInstaller(); 
#endif 

container.Install(installer); 
相关问题