2010-04-23 56 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); 
相關問題