开发者

How to scope NHibernate sessions and transactions in a WPF application

I am relatively new to both WPF and NHibernate and attempting to build an application that combines the two, using the MVVM pattern. However, I am struggling to understand when and where my application should open and close NHibernate sessions and transactions.

From what I have read, it is recommended that sessions should be kept as short as possible. Therefore, aside from the obvious thread-safety considerations, I assume it is not correct to open a session at the application level and share it aro开发者_如何学JAVAund? On the other hand, I also realize that very short sessions (scoped within business methods) will result in detached entities and also prevent me from exploiting NHibernate's lazy loading. Is this a normal and unavoidable way to design a WPF/NH application?

Unfortunately all the good code samples (and the only book I can find on this topic - NHibernate in Action) are focused towards ASP.NET applications, where the best practice is apparently fairly clear cut - a session and a transaction span exactly one Http request.

So, I would appreciate some guidance from WPF developers, to help me to understand session management in WPF (ideally pointing me to some good code samples).

Many thanks,

Tim


Here is one of the best NHibernate desktop application samples that I am aware of (I believe it was written with WPF in mind):

Building a Desktop To-Do Application with NHibernate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜