NServicebus:在配置文件中设置连接字符串

时间:2010-07-02 17:40:51

标签: nservicebus

是否可以创建包含连接字符串的配置文件或指向app.config中的连接字符串?我希望有一个项目可以根据执行NServicebus.Host.exe时传递的配置文件创建多个服务。

这样的事情:

public class Warehouse1 : IProfile
{
     // Code goes here to set the connection string to the Warehouse1 DB
}

public class Warehouse2 : IProfile
{
     // Code goes here to set the connection string to the Warehouse2 DB
}

当我执行“NServicebus.Host.exe Warehouse1”时,我希望我的发布者使用我设置的连接字符串,并在执行“NServicebus.Host.exe Warehouse2”时使用不同的连接字符串。

1 个答案:

答案 0 :(得分:1)

您可以将连接字符串包装在接口后面并执行:

public class Warehouse2ProfileHandler:IHandleProfile {

public void ProfileActivated

{        //使用nsb api

Configure.Instance.RegisterSingleton(new Warehouse2CSProvider());

//或使用您选择的容器 //....

}

}

有关生命周期意识的更多内容:(自从我撰写帖子后语法发生了变化,但你会明白这一点)

http://andreasohlund.blogspot.com/2009/09/building-lifecycle-aware-applications.html

希望这有帮助!

相关问题