NHibernate is one of the most useful and complicated open-source projects in the .NET community. Some consider NHibernate prohibitively difficult. It can be quite difficult and frustrating, especially when you only want to use it to build a simple, prototype, or startup-size web site. That's where NHQS fits in.
A lot of developers want to use NHiibernate, or Fluent NHibernate, or some flavor therein, but don’t want to learn the layers and layers of how-and-why it works just to get up and running. NHQS should mitigate this confusion and ease the transition into usage of NHibernate. A secondary goal of NHQS is to make it easy for a developer to have access to any and all persistent storage mechanisms supported by NHibernate in a fluent and domain-centric manner. At the highest level, a developer facilitating object persistence via NHQS should neither need to know nor be exposed to the underlying persistence mechanism.
You can grab NHQS as a NuGet package by using the NuGet package explorer or entering the command below at the NuGet command line within Visual Studio 2010.
To accomplish that goal we’re going to walk through the steps of setting up and using NHQS to access multiple databases via the almost-too-simple-to-be-legit fluent/generic interfaces exposed almost solely via extension methods. I’m sure I’ll get burned at the stake for failing to follow someone’s NHibernate Best Practice 101 list, so I’ll apologize up front. With that, here’s the synopsis of the blog series, which I aim to complete by the end of this week.
- Introduction (this post)
- Session Factory Creation and Containment
- Session Fluency Extensions
- Transactions and Multiple Database Support
NHQS in 30 Seconds
There are a few steps one must follow to get their persistence mechanism accessible via NHQS. Here they are:
- Implement the ISessionFactoryCreator interface via a class of your own (we’ll cover this in a moment)
- Add code to the startup of the calling application (or in your TestFixtureSetup method) that calls the Create method of that class to create an NHibernate ISessionFactory object instance
- Take the resultant ISessionFactory and store it using the SessionFactoryContainer class
- Write DDD-like code to get objects from databases and perform CRUD operations via an arsenal of extension methods attached to areas of NHibernate
The second post in this series will begin the process of using NHQS in a real-world situation by simplifying the art of creating ISessionFactories and storing them in a container, so check back soon.
If you’d like to skip the blogs and look at the source, feel free, I keep the NHQS source in Github.