views:

82

answers:

1

Hi ! This question is purely AR related.

Let's say I have 2 layers in my web/wcf application - DataLayer and BusinessLayer. DataLayer contains almost atomic operations that work on mappings (find, get, save, special find, cross find , etc. :) ). There is a lot of HQL or Criterias. There's no SessionScopes used in this layer. Some of my mappings contain lazy collections.

Now, the BL layer has methods that contain business logic included mixed with DL calls - that's normal. For each public method that have readonly operations inside I have SessionScope(FlushAction.Never) specified. For all those methods that have some Save or Update operations, I'm using TransactionScope(), with try catch inside, with direct VoteCommit at the end of the method and VoteRollback inside catch clause. I have ReadCommitted set as isolationLevel.

For basic situations this works. I started to have real problems when I wrote methods that uses other methods with their own transactions inside - I'm talking about locks. For example I have method with transaction that is recursive. It seems that some 'read' methods (that have their own SessionScope(FlushAction.Never)) are blocked because of other transactions.

I can't really track down what exactly is wrong, but I'm starting to think that I have some major design problem.

Help on castle site doesn't do much for me, also tests in AR sources - they are simply too basic for me.

Can anyone really explain how should I use the TransactionScopes or what's my mistake?

+1  A: 

I recommend using Castle.Service.Transaction, it allows you to do transactions declaratively instead of explicitly. This is typically used through the Automatic Transaction Management facility, but it requires Windsor.

Mauricio Scheffer
Well, I've implemented the session-per-request approach.Do you think it still makes more sense to use Windsor package?
StupidDeveloper
@StupidDeveloper: If you want to use transactions, yes. If you don't need transactions, then no.
Mauricio Scheffer

related questions