views:

44

answers:

2

TransactionScope is an amazing feature but too few providers do implement it correctly. I don't want to pass the connection as parameter.

A: 

Maybe you're looking for System Prevalence.

Basically, every transaction is journaled (the details of the transaction are saved) and if the application crashes and is restarted you can either pick up where you left off or rollback the changes based on the journaled state.

Here's a link to the Snapshot pattern that can aid you in implementing System Prevalence.

Jonn
+1  A: 

Not sure what you wanted to achieve using TransactionScope here - if idea is to have auotmatic flow of transactions across methods (and simple enlistment within ongoing transaction) then passing connection as parameter is not the only way. You can pass current connection and transaction using current CallContext (or Current Thread). Put a simple static wrapper that would check if connection/transaction exists on current call context and creates if not. This is transparent non-intrusive way as opposed to passing by parameter.

Now, if you are looking at flowing transactions across app domain boundaries and/or using multiple resource managers (i.e. using distributed transactions) then the best bet would be to use TransactionScope and roll out your own ResourceManager. Of course, this is not a trivial thing but then that's what the requirement entails. If underlying system does not provide transactional resource then custom resource manager can use compensating transaction for having roll backs (for example, a manager on a top of file system can use "Delete Folder" as compensating transaction against original transaction of "Create Folder").

VinayC
I was thinking about using ThreadStatic variables but CallContext is exactly what I needed! Thank you very much VinayC.
Eduardo