user610217
user610217

Reputation:

(How) can I specify a specific configuration file name for my nhibernate configuration?

I'm using an NHibernateProvider library I found online, and I want to keep security and profile information separate from a collection of application databases I'm using; I intend to centralize the application services, but most applications will have their own database.

Googling nhibernate with multiple databases generates a long list of shockingly complicated processes. I thought it would be simpler if I hardcoded a reference to nhibernateprovider.config and reference only that in the provider library to avoid any issues with potential conflicts with core applications also using nhibernate. It seemed like a really simple idea, and I like simple... however, I cannot figure out any place to specify a configuration file when instantiating my session factory. Googling generates too many unrelated hits.

  1. Is it possible to explicitly specify a configuration file when instantiating a session factory, and if so,
  2. How do you do it?
  3. If it isn't possible, why the heck not? This seems to be an obvious thing.

Upvotes: 1

Views: 380

Answers (1)

Firo
Firo

Reputation: 30813

string configfile = "myNhibernate.config";
var config = new Configuration().Configure(configfile);

you can also share common information in the configfile and set the connectionstring dynamically befor constructing the sessionfactory

config.Properties[NHibernate.Cfg.Environment.ConnectionString] = connectionstring;

Upvotes: 3

Related Questions