I have the following implementation and would like some feedback as to whether it makes correct use of NHibernate for sessions and transactions.
public inter
I have a mostly CRUD type of application, and I implemented the Unit Of Work with Repository pattern, but couldn't really get away from the Session/Transaction split. Sessions and Transactions need different lifetimes. In the desktop world, a Session is usually "per-screen" and a Transaction is "per-user-action".
More information in this excellent article.
So what I ended up with was:
IUnitOfWork
-> Wraps session, implements IDisposable
IAtomicUnitOfWork
-> Wraps transaction, implements IDisposable
IRepository
-> Provides Get, Save, Delete and query accessI made it so that you need an IUnitOfWork
to build an IAtomicUnitOfWork
and you need an IAtomicUnitOfWork
to build an IRepository
, so that enforces proper transaction management. That's really all I gained by implementing my own interfaces.
As jeroenh said, you are almost just as well to use ISession
and ITransaction
but in the end I felt a little better writing all my code against an interface that I defined.