NHibernate best practices

Edit this page | less than 1 minute read

As I'm in the process of introducing NHibernate into a reusable architecture based on Microsoft's Web Client and Web Service Software Factories, I've been struggling with several decisions. Should I encapsulate access to NHibernate classes in some data access layer? Where do I keep its ISessionFactory instance in a IIS-hosted WCF service? Should I have default transactions for each service interface request? Who is responsible for committing or rolling back the transaction?

Anyway, while looking for best practices, I ran into a great article by Billy McCafferty that not only covers many of my issues, it also presents some great design patterns and ideas that I've been adapting since then. Notice that his article mentions NHibernate getting support for C# Generics and Nullables soon.
Well, I have been using version 1.2.0 RC1 for a few weeks now, and it works like a charm. You can now define associations as ISet, IList or any of the other generic collections, and using types like int? or float? is a natural choice as well.


Leave a Comment