2012-10-22 17 views
0

我有一個SqlWorkflowInstanceStore對象,我想使用CastleWindsor爲我創建。 SqlWorkflowInstanceStore採用連接字符串的構造函數參數。 我的連接字符串在我的app.config中。如何使用CastleWindsor來解析SqlWorkflowInstanceStore

不使用CastleWindsor這個工程:

InstanceStore persistanceStoreX = new SqlWorkflowInstanceStore(ConfigManager.Instance.GetSQLConnectionString()); 

我已經試過這些片段與CastleWindsor:

WindsorContainer.Register(Component.For<InstanceStore>().ImplementedBy<SqlWorkflowInstanceStore>().DependsOn(Property.ForKey("InstanceStore").Eq(ConfigManager.Instance.GetSQLConnectionString()))); 

var connString = ConfigManager.Instance.GetSQLConnectionString(); 
WindsorContainer.Register(Component.For<InstanceStore>().ImplementedBy<SqlWorkflowInstanceStore>().DependsOn(new { InstanceStore = connString })); 

當這個解決:

_persistanceStore = _iodManager.WindsorContainer.Resolve<InstanceStore>(); 

我得到一個有效的容器,但它有一個空的ConnectionString字段。

什麼是初始化SqlWorkflowInstanceStore的正確方法?

InstenceStore是抽象類基礎SqlWorkflowInstanceStore ConfigManager.Instance.GetSQLConnectionString()是一個單獨的實例

回答

1

通過觀察this page,它出現在SqlWorkflowInstanceStore構造函數參數取一個叫connectionString所以我覺得您的註冊參數代碼應該是:

WindsorContainer.Register(Component.For<InstanceStore>().ImplementedBy<SqlWorkflowInstanceStore>().DependsOn(Property.ForKey("connectionString").Eq(ConfigManager.Instance.GetSQLConnectionString()))); 
+0

Ta。這樣可行。我使用的是抽象類中的參數名稱,而不是具體的(我認爲) – Richard210363

相關問題