|
Project Information
Links
|
Unit of Work with NHibernateDisclaimer: AFAIK, there is no official or credible definition of the "Unit of Work pattern." This work is merely a product of my interpretation of what I feel is the proper implementation - that is, an easy-to-use facade of NHibernate's existing "Unit of Work" features. IntroductionNHibernate already supports "Unit of Work" behavior via it's transaction methods. So what's the purpose of this project? NHibernate is a very powerful and flexible ORM, capable of handling the largest of tasks. However, not all projects require this level of flexibility and could stand to have NHibernate be a little simpler. This project provides an easy-to-use class (NHUnitOfWork) that simplifies NHibernate's transactional features and will give you a head start on building your data access layer. Comparison to plain NHibernatePlain NHibernate ISessionFactory sessionFactory = GetSessionFactory();
using (ISession session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.SaveOrUpdate(myObject);
transaction.Commit();
}
session.Close();
}Unit of Work using (var uow = new NHUnitOfWork(Properties.Settings.Default.DBConnStr))
{
uow.Save(myObject);
}
|