Is a static repository a right way to use NHibernate?

前端 未结 2 1051
暖寄归人
暖寄归人 2020-12-23 18:26

I spent the rest of the evening reading StackOverflow questions and also some blog entries and links about the subject. All of them turned out to be very helpful, but I stil

2条回答
  •  情话喂你
    2020-12-23 18:53

    We have mixed ASP.NET/Windows Forms applications and the best solution I've found is to do manual dependency injection through the repository constructor. That is, every repository class has a single public constructor that requires an ISession. This allows the application to have complete control over the unit-of-work and transaction boundaries. It's simple and effective. I also have a very small NHibernate helper assembly that configures the session factories and provides methods to open a regular or context session.

    There are a lot of things I like about S#arp Architecture and I think that it's worth studying how it works, but I found it to be over-architected for my tastes.

提交回复
热议问题