I'm glad to see I'm not the only one trying to combine NHibernate and WinForms, especially for the session management part.
Me too, I have started creating some kind of architecture - framework, mainly as a POC. If it proves to be useful I will try to convince the developers at work to use it.
Before I started, I put forward the following requirements:
- Domain driven (usage of business entities for wrapping data and business logic)
- Database independent
- Scalability: no "long" connections towards the database
- Local unit-of-work per use case
- Unit-of-work should only commit the modifications to the data at the end of the use case
- UI-Binding logic should be as independent as possible of the business logic
(mainly for reasons compatibility with our legacy VB6 ORM and so keep the learning curve for our developers low)
Translated to NHibernate language, this means that I have a long-lived session that will typically be created by one WinForm (or a controller) but can be passed to any sub-usercontrol necessary. In the end, it should be the creatot that has the responsability to either commit or rollback the whole session.
I use a subset of the CSLA framework to handle the GUI binding.
The code is available here:
http://www.paarden.be/nhibernate/Sol_Pa ... urator.zip
I would be glad to hear your opinion!
One thing that I should take care of is the defering of the session.Save() and session.Remove() methods. Maybe by implementing some custom unit-of-work on top of the hibernate session.
Another thing is to add a service-layer to abstract the GUI part of the NHibernate code.
Tolomaüs.