tags:

views:

27

answers:

1

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".

+1  A: 

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!

Andreas