NHibernate with StructureMap for a non web application

What are the best pricing to implement and manage session / transaction for NHibernate using StructureMap for a non-web application like Windows service?

In web context, we are using PerRequest session management lifecycle using StructureMap hybrid lifecycle, but for windows service, I cannot handle IDisposable UnitOfWork ...

Thanks.

+2


a source to share


1 answer


Ayende gives a good summary on how to deal with NHibernate in a desktop application here .

With StructureMap, I first create the ISessionFactory manually. Then declare an instance to be used across all ISessionFactory instances:

        For<ISessionFactory>().Use(sessionFactory);

      



This way you leave the screens to create and delete your sessions yourself. It is important that all sessions are isolated from each other to avoid memory problems. This is explained in detail in the article.

With this approach and good use of IStatelessSession as needed, I narrowed down many of the problems I had in my WPF / StructureMap / NHibernate application.

+2


a source







All Articles