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”时使用不同的连接字符串。
Is it possible to create a profile that contains a connection string or points to a connection string in the app.config? I'd like to have a single project that can create multiple services based on which profile is passed when I execute NServicebus.Host.exe.
So something like this:
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
}
When I execute "NServicebus.Host.exe Warehouse1" I want my Publisher to use the connection string I set and use a different connection string when I execute "NServicebus.Host.exe Warehouse2".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将连接字符串包装在接口后面并执行以下操作:
public class Warehouse2ProfileHandler : IHandleProfile
{
公共无效配置文件激活
{
//使用nsb apiConfigure.Instance.RegisterSingleton
(new Warehouse2CSProvider());
//或者使用您选择的容器
//....
}
}
有关生命周期意识的更多信息,请参见此处:(自从我写这篇文章以来,语法已发生变化,但您会明白的)
http://andreasohlund.blogspot.com/2009/09/building-lifecycle-aware-applications.html
希望这有帮助!
You could wrap your connection string behind a interface and do:
public class Warehouse2ProfileHandler : IHandleProfile
{
public void ProfileActivated
{
//using the nsb api
Configure.Instance.RegisterSingleton(new Warehouse2CSProvider());
//or use your container of choice
//....
}
}
More on lifecycle awareness here: (the syntax has changes since I wrote the post but you'll get the idea)
http://andreasohlund.blogspot.com/2009/09/building-lifecycle-aware-applications.html
Hope this helps!