3
我有在被在我的Application_Start方法中使用的Autofac模塊以下代碼:如何使用Autofac確保每個請求都有一個NHibernate ISession?
builder.Register(c => new Configuration().Configure().BuildSessionFactory())
.SingletonScoped();
builder.Register(c => c.Resolve<ISessionFactory>().OpenSession())
.HttpRequestScoped();
builder.Register<NHibernateSomethingRepository>().As<ISomethingRepository>();
存儲庫的構造函數一個ISession作爲參數。但是我最終得到了整個應用程序的一個會話,儘管我明確要求它是HttpRequestScoped。
我已經配置了ContainerDisposal HTTP模塊。
根據documentation你必須創建一個嵌套的容器,但我讓Autofac autowire依賴關係。
我該怎麼辦?
謝謝!
注意:在Autofac2中,默認設置已經更改 - 現在是:'factoryScoped'AKA'InstancePerDependancy'在新的說法中。 – UpTheCreek 2010-05-08 15:30:29