开发者

WPF, Nhibernate v2 Session Persistence

I have a WPF application that loads modules into my application via prism / MEF. Each module will reference an assembly I created to house NHibernate functionality (Unit of Work & repository pattern). Now that I started on the first module, the following questions came up:

  • Is it common place to have an nhibernate session open for the lifetime of a WPF / windows application?
  • Would it be a good idea to share the nhibernate session amongst all modules or have each module create its own session?

It's my understanding that the session is lightweight, so opening and closing a session is not a problem... however, if I close the session then I lose the change tracking... when I call Save, and the object is the same as when it was retrieve, I do 开发者_运维问答not want a query to be executed.


  1. Do not have the session open for a the lifetime of a wpf/windows application. You will have performance and memory problems if you do.

  2. It really depends how these modules interact. Are they separate systems, or do they need to work in tandem to do work. If it's the former, I would say that they shouldn't share sessions. If it's the latter, I would use some kind of session manager that can pass out the current session.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜