是否有可能使用類似這個包裝與流利的配置?使用nHibernate包裝與流暢的nHibernate
http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/
如果是這樣,在那裏我會加上流利的配置?
此外,這是否適合在asp.net和windows應用程序中使用? 我打算使用存儲庫模式,使用它來創建我的nHibernate會話?
是否有可能使用類似這個包裝與流利的配置?使用nHibernate包裝與流暢的nHibernate
http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/
如果是這樣,在那裏我會加上流利的配置?
此外,這是否適合在asp.net和windows應用程序中使用? 我打算使用存儲庫模式,使用它來創建我的nHibernate會話?
在GetConfiguration
方法在你SessionBuilder
,而不是你的鏈接頁面顯示的
public Configuration GetConfiguration()
{
var configuration = new Configuration();
configuration.Configure();
return configuration;
}
,簡單地做這樣的事情:
public Configuration GetConfiguration()
{
return Fluently.Configure()
.Database(/* your database settings */)
.Mappings(/* your mappings */)
.ExposeConfiguration(/* alter Configuration */) // optional
.BuildConfiguration();
}
至於有關處理環境的進一步詢問,你會有兩個類繼承ISessionBuilder
,例如AspSessionBuilder
和WinAppSessionBuilder
,併爲當前項目注入適當的一個。您應該使用Jamie Ide也posted as an answer概述的策略處理上下文而不是使用HttpContext
。你只需簡單地要修改此行:
.ExposeConfiguration(x => x.SetProperty("current_session_context_class", "web")
喜歡的東西"call"
或"thread_static"
。針對不同情境會話類型的一個很好的解釋見NHibernate的鍛造維基此頁:
是的,你可以使用它,但它最好使用NHibernate的內置的情境會話管理,而不是自己處理。看到我的回答this question。除了較少的編碼之外,它還提供了除HttpContext,Call和ThreadStatic之外的兩個其他選項。
不錯,謝謝...這是否適合除asp.net以外的其他應用程序? - 我打算在windows服務中使用我的存儲庫也是 – Alex 2010-04-07 22:46:01
是的。你應該沒問題。我在我所有的應用程序中使用類似的存儲庫模式。 – snicker 2010-04-07 22:47:02
謝謝:-)在該鏈接的例子中,有getExistingOrNewSession - 它檢查HttpContext - 在Windows應用程序中使用它時如何工作? – Alex 2010-04-08 08:40:55