如何使用CastleWindsor解析SqlWorkflowInstanceStore

时间:2012-10-22 15:56:35

标签: c# castle-windsor

我有一个SqlWorkflowInstanceStore对象,我想使用CastleWindsor为我创建。 SqlWorkflowInstanceStore接受连接字符串的构造函数参数。 我的连接字符串在我的app.config中。

不使用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的Abstract类库 ConfigManager.Instance.GetSQLConnectionString()是一个单例实例

1 个答案:

答案 0 :(得分:1)

通过查看this pageSqlWorkflowInstanceStore的ctor参数显示了一个名为connectionString的参数,因此我认为您的注册码应为:

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