views:

796

answers:

3

Very new to FluentNHibernate, but I'm also excited about the area. I've recently started work on a new DAL using the aforementioned and have been reading up on the Repository pattern. I like the generic form this pattern takes and am looking to use this pattern in conjunction with the UnitOfWork pattern for session management.

I'm curious, is this the right direction to head? Should I be using UoW to create a pseudo-singleton NHibernate session? This question really dances around the topic of NHibernate session management. There is a UoW implementation available that I've taken a look at, although I'm also unclear if I should be working to implement this library, or abstract my own.

EDIT:

Just for re-clarification of the question:

Is it common practice to use the UoW pattern with the Repository pattern in a FluentNHibernate environment?

+3  A: 

You can check the series of blogs regarding how to implement UOW using Nhibernate

NHibernate and the Unit of Work Pattern - Part1

NHibernate and the Unit of Work Pattern - Part2

NHibernate and the Unit of Work Pattern - Part3

Liang Wu
Great tutorials no doubt, but is it common practice to use the UoW pattern in conjunction with the Repository pattern?
Alexis Abril
Yes, it is correct.
Liang Wu
+1  A: 

Yes, for a good example check out FubuMVC-Contrib's implementation of these.

mxmissile
+2  A: 

I see a lot of "can I do X with Fluent NHibernate" questions - just to clarify Fluent NHibernate sits on top of NHibernate and spits out those horrible XML mappings for you... it doesn't affect what you can and can't do with NHibernate.

DanB
Thank you for the response DanB. Actually, the fact that I'm using Fluent doesn't affect the above question. I'm referring to the ability of using the Repository pattern for persistence in conjunction with the Unit Of Work pattern for session management and was confused on the idea of them coinciding. NHibernate was only noted as session management might be unique(ie, LINQ sessions are another story entirely).
Alexis Abril
Fair point - back on topic: I found the following useful for getting my head around the UoW pattern: http://www.codeinsanity.com/2008/09/unit-of-work-pattern.htmlhttp://www.codeinsanity.com/2008/10/implementing-persistence-ignorant-unit.htmlwhich borrows heavily from Ayende's work in Rhino Commons http://ayende.com/wiki/Rhino+Commons.ashx
DanB