I need some advice on NHibernate Session Management for a C# WinForms application.
I am currently porting an application to use NHibernate. I am also employing a UnitOfWork pattern as described in the link below;
http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx
My question relates to Sessions.
Can you only have one session running per thread at all times?
I have a scenario in which a Session (UnitOfWork) may be open for a form shown by the application but the user opens another form (i.e. Tools - Options) which I would like to have its own UnitOfWork. Clearly in this instance it would make more sense to open another Session for the "Tools - Options" form and not use the currently open session for the underlying form.
Can we have a Dictionary of Sessions on the one thread?
Any advice on session management is appreciated.
+1 on what Jay said. I would also recommend reading Oren Eini's article on Building a Desktop To-Do Application with NHibernate:
http://msdn.microsoft.com/en-us/magazine/ee819139.aspx
It uses WPF as the UI technology, but everything he says (wrt NHibernate in desktop apps) is equally relevant for WinForms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With