title: NHibernate session management in ASP.NET MVC
body: <p>I am currently playing around with the HybridSessionBuilder class found on Jeffrey Palermo's blog post:</p>
  
  <p><a href="http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/" rel="noreferrer">http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/</a></p>
  
  <p>Using this class, my repository looks like this:</p>
  
  <pre><code>public class UserRepository : IUserRepository
  {
      private readonly ISessionBuilder _sessionBuilder;
  
      public UserRepository(ISessionBuilder sessionBuilder)
      {
          _sessionBuilder = sessionBuilder;
      }
  
      public User GetByID(string userID)
      {
          using (ISession session = _sessionBuilder.GetSession())
          {
              return session.Get&lt;User&gt;(userID);
          }
      }
  }
  </code></pre>
  
  <p>Is this the best way to go about managing the NHibernate session / factory?  I've heard things about Unit of Work and creating a session per web request and flushing it at the end.  From what I can tell, my current implementation isn't doing any of this.  It is basically relying on the Repository to grab the session from the session factory and use it to run the queries.</p>
  
  <p>Are there any pitfalls to doing database access this way?</p>