The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008
Sign in
I've recently become interested in using NHibernate for some of my data access. For the past year or so I have been using SubSonic for that, however, I'm trying to take a bit more of a domain driven approach on the project I'm currently messing around on. Although I've only been looking at it for a couple of days, one thing I'm having a little bit of trouble figuring out is where my ISession should be opened / closed in an ASP.NET MVC application. Currently, I'm doing this in the Controller but I'm not totally sure that is the right way to go...
public ActionResult ViewProduct(string ID)
{
using (ISession session = SessionManager.GetCurrentSession())
SimpleProductRepository repo = new SimpleProductRepository(session);
return RenderView("ViewProduct",
new SimpleProductRepository(session).GetByTitle(ID));
}
May 2. 2008 07:51
You want this to be transparent to your controller... Use something like this www.codeproject.com/.../...rnateBestPractices.aspx or Jeffrey Palermo's HybridSessionBuilder w/ Session per request palermo.googlecode.com/.../...nateSessionModule.cs or Unit Of Work rhino-tools.svn.sourceforge.net/.../...lication.cs
Matt Hinze
May 2. 2008 08:18
@Matt: Thank you for the links! I will have to play around w/ these options a little more but they look great -- I knew how I was using the session was less than ideal.
Ryan Lanciaux
July 23. 2008 23:08