I have a service, business and data access layer. In which layer should I implement transactions using asp.NET transactionscope? Also, is nesting Transactions a good thing because I had problems with that?
views:
217answers:
1
+2
A:
Transaction Scope is part of .net not specific to asp.net
We would place the tansaction scope in the business layer. The service layer is more of a facade. If something requires a transaction it should be within a single business operation.
Shiraz Bhaiji
2009-11-01 12:03:51
So a service should never call two business functions? If that were the case and the two functions would need to be called in one transaction, then you would have to define a transactionscope in the service? And then you would have nested transactions... (because the two functions in business layer would already be each in a transactionscope). Or can you easily nest transactionscopes?
Lieven Cardoen
2009-11-01 12:13:48
Yes, you can nest transaction scopes, check this link http://stackoverflow.com/questions/1334366/hierarchy-of-transactionscope You need to make sure that you commit each transaction scope when you have nested scopes.
Shiraz Bhaiji
2009-11-01 12:22:50
Well, I tried that, and the inner transaction scope was committed twice, once because of the commit of the inner transaction scope, but also once because of the outer transaction scope. So I would have to look into that again, but is this known behavior?
Lieven Cardoen
2009-11-01 12:56:19