开发者

NHibernate with StructureMap for a Non-Web Application

开发者 https://www.devze.com 2022-12-30 10:12 出处:网络
What is best pratices for inject and manage Session/Transaction for N开发者_Python百科Hibernate using StructureMap for a Non Web Application like an Windows Service ?

What is best pratices for inject and manage Session/Transaction for N开发者_Python百科Hibernate using StructureMap for a Non Web Application like an Windows Service ?

In a web context, we use PerRequest Session management lifecycle using the Hybrid Lifecycle of StructureMap but for a Windows Service, i can't handle IDisposable UnitOfWork ...

Thanks.


Ayende gives a good summary of how to handle NHibernate in a desktop application here.

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

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

Thus, you leave the Screens themselves to create and dispose of their sessions. It's important that all sessions are isolated from one another to avoid memory problems. This is explained in full in the article.

With this approach, and with the good use of the IStatelessSession as needed, I've cut down on a lot of the issues I have had in a WPF/StructureMap/NHibernate application.

0

精彩评论

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