I use this approuch http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/ for setting up fnh with structuremap but after one request I get the following exception
Session is closed! Object name: 'ISession'.
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.
Exception Details: System.ObjectDisposedException: Session is closed! Object name: 'ISession'.
My repository class looks like this:
public class Repository : IRepository {
private readonly ISession _session;
public Repository(ISession session) {
_session = session;
}
public T Get<T>(Expression<Func<T, bool>> predicate) {
return _session.CreateCriteria(typeof(T)).Add(predicate).UniqueResult<T>();
}
and I register my repository in structuremap like this:
public class RepositoryRegistry : Registry {
public RepositoryRegistry() {
Scan(a => {
a.AssembliesFromApplicationBaseDirectory();
a.AddAllTypesOf<IRepository>();
});
}
}
How can I prevent the session from being closed?