title: Setting up Fluent NHibernate and StructureMap for a web application
body: <p>I use this approuch <a href="http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/" rel="nofollow">http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/</a> for setting up fnh with structuremap but after one request I get the following exception</p>
  
  <p>Session is closed!
  Object name: 'ISession'.</p>
  
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.ObjectDisposedException: Session is closed!
  Object name: 'ISession'.</p>
  
  <p>My repository class looks like this:</p>
  
  <pre><code>public class Repository : IRepository {
      private readonly ISession _session;
      public Repository(ISession session) {
          _session = session;
      }
      public T Get&lt;T&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; predicate) {
          return _session.CreateCriteria(typeof(T)).Add(predicate).UniqueResult&lt;T&gt;();
      }
  </code></pre>
  
  <p>and I register my repository in structuremap like this:</p>
  
  <pre><code>public class RepositoryRegistry : Registry {
      public RepositoryRegistry() {
          Scan(a =&gt; {
              a.AssembliesFromApplicationBaseDirectory();
              a.AddAllTypesOf&lt;IRepository&gt;();
          });
      }
  }
  </code></pre>
  
  <p>How can I prevent the session from being closed?</p>