How does UnitOfWork attribute work?

64 views
Skip to first unread message

Ismu the dev

unread,
Mar 19, 2011, 4:49:16 PM3/19/11
to sutekishop
Can anyone please help me understand how is UnitOfWork pattern used in
it with MVC? Or if at least can point me to some article/blog which
explains?

Thanks in advance.

Mike Hadlow

unread,
Mar 20, 2011, 7:59:22 AM3/20/11
to sutekishop
Hi Isumu.

Note that the UnitOfWorkAttribute is implemented in Suteki Shop, it's
not an MVC component.

The UnitOfWorkAttribute in Suteki Shop is responsible for managing the
NHibernate transaction for an MVC action. It's implemented as an
action method. Suteki Shop uses the Windsor NHibernate facility to
manage NHibernate sessions on a session-per-request basis. So at the
start of each request the facility creates a new NH session instance.
The UnitOfWorkAttribute creates a new NH transaction just before the
action method is started and then commits it just after the action
method completes. If there's an either an Exception thrown or the MVC
ModelState is invalid, it rolls back the transaction.

I'm planning to also move the session handling into the UnitOfWork
attribute and retire the NH Facility, because there are some awkward
cases when there are several actions being run on a single request (as
is the case when you use RenderAction).

I hope this helps,

Mike
Reply all
Reply to author
Forward
0 new messages