I am developing a Data Access Layer using NHibernate. It will be used in my business logic layer. My application is a collection of several other applications (ASP.NET MVC, Windows Services, Windows Forms, ASP.NET Web API), all of them will use the same business logic level. The level of business logic will reach the level of data access. Applications will not directly access the data access layer.
I know that I should NOT depend on an implicit transaction and should include all database calls (including READ calls) in an explicit transaction.
In my understanding, the transaction should be short. If he lives long, it can create problems. Refer to 1 and 2 .
Many resources (on StackOverflow and other sites) suggest including the transaction code in the block using. This really makes sense as it helps to use an explicit transaction for every database call. It also helps to make the transaction short. The problem with this approach is that batch processing is limited to block only using. UnitOfWorknot fully used.
On the other hand, many resources (on StackOverflow and other sites) involve using a transaction at a higher level, such as web-request(session per request) in a web application or "for each window form" in WinForms, etc. This improves batch request processing and it is better to use a template UnitOfWork. The problem with this approach is that transactions are long-lived.
1] .
1 - Caller . , .
2 - , - , , " " " ". , / . , . , , Business Logic Layer ?
2] -.
. UnitOfWork. BLL , .
Begin Commit, UnitOfWork?
1: ( )
UnitOfWork. :
: . . ; . , SQL , SQL- ad-hoc.
. . , , . .
- . , Hibernate. Hibernate, . , , , . , . , .
. - , . - , .
, . (, , , ). , . , , . , , , .