UnitOfWork Action filter for ASP.NET MVC and nHibernate

Published Tuesday, July 27, 2010 4:26 PM by Fredrik N

Comments

# re: UnitOfWork Action filter for ASP.NET MVC and nHibernate

Tuesday, July 27, 2010 12:13 PM by Niclas Pehrsson

What is the difference to send around ISessionFactory and use ISessionFactory.GetCurrentSession() with the usage of NHibernate.Context.ManagedWebSessionContext in the configuration? Instead of create your own session holder? Of course you need to bind and unbind the session to the context as you do in ActionFilter, but the rest is only inventing the wheel again :).

# Dew Drop – July 28, 2010 | Alvin Ashcraft's Morning Dew

Wednesday, July 28, 2010 8:12 AM by Dew Drop – July 28, 2010 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop – July 28, 2010 | Alvin Ashcraft's Morning Dew

# re: UnitOfWork Action filter for ASP.NET MVC and nHibernate

Wednesday, July 28, 2010 5:44 PM by Ryan

I encountered a hidden problem with this approach and delayed execution of queries (via IQueryable and EF4). Seemed like a good route to take, until we started disposing the connection in ActionExecuted, and discovered that the view result isn't executed as part of the action (of course!), but instead happens after the action is complete. The result was exploding views where the connection was disposed when it attempted to execute the query. I had to move to Dispose() call into OnResultExecuted, which solved that problem.

Leave a Comment

(required) 
(required) 
(optional)
(required)