## Configure NHibernate with Embedded Resource

I spent a couple dozen minutes figuring this out today. There are several different ways to configure NHibernate:

1. The default way, which is having a hibernate-section configuration section in your app.config, or having a hibernate.cfg.xml in the root of your app.
2. Embedded resource
3. Hard-coded path to config file

In my app, I have some tests that spin up a database and test out some NHibernate-related stuff, like that things cascade properly. So that means I needed a hibernate.cfg.xml file for my test assembly as well. And that sucked, because I didn't want to put it at the root of the application because it cluttered up the directory and I have a disorder regarding stuff like that.

So, I left the hibernate.cfg.xml file in my non-root directory, and turned it into an embedded resource.

Now you have to figure out the manifest resource name of this embedded resource, which is just the path to the file on disk.

//assuming this class and hibernate.cfg.xml reside in the same directory
new NHibernate.Cfg.Configuration().Configure(
GetType().Assembly,
"My.Sweet.App.NotTheRootDirectory.hibernate.cfg.xml"
);

And then you profit.