我在使用 Windsor、设施和 nhibernate 配置应用程序时遇到问题。
我得到这个例外:
ObjectDisposedException: Session is closed
温莎不应该照顾每个请求的实例化会话并在我有这样的配置时打开它吗?我可以错过一些配置吗?这是我的配置:
public class PersistenceFacility : AbstractFacility
{
protected override void Init()
{
Configuration config = BuildDatabaseConfiguration();
Kernel.Register(
Component.For<ISessionFactory>()
.LifeStyle.Singleton
.UsingFactoryMethod(config.BuildSessionFactory),
Component.For<ISession>()
.LifeStyle.PerWebRequest
.UsingFactoryMethod(k => k.Resolve<ISessionFactory>().OpenSession()));
}
private Configuration BuildDatabaseConfiguration()
{
return Fluently.Configure()
.Database(SetupDatabase)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<RnUlice>())
.ExposeConfiguration(ConfigurePersistence)
.BuildConfiguration() ;
}
......
}