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?
The error seems to occur in my sitemapprovider. Because the
constructor must have an empty default constructor I use
ObjectFactory.GetInstance<IRepository>() in the constructor and that
seems to be the problem?
public class MvcSiteMapProvider : SiteMapProvider {
private IRepository _repository;
public MvcSiteMapProvider() {
_repository = ObjectFactory.GetInstance<IRepository>();
}
}
This is the output from ObjectFactory.WhatDoIHave()
pastebin.com/
57dRSR8m