是否可以有條件地解析爲基於MVC的行動正確ISession
範圍屬性?是否有可能有Ninject綁定範圍條件?
Bind<ISession>().ToMethod(ctx => (ISession)NHibernateHelper.Open())
.InRequestScope();
Bind<ISession>().ToMethod(ctx => (ISession)NHibernateHelper.Open())
.InSessionScope();
僞的可能解決方案代碼:
Bind<ISession>().ToMethod(...).InSessionScope()
.WhenActionHasAttribute(LongConversation);
// else use this binding
Bind<ISession>().ToMethod(...).InRequestScope()
也許我的做法是錯誤的,我打開我的問題altnerative解決方案。
根據網頁「對話」的類型,我需要或者保持NHibernateSession
各地的HTTP請求/響應或HTTP會話。大多數會話只持續一個HTTP請求/響應。
注:InSessionScope
按Fredrik Kalseth