I'm getting annoyed with writing the following code all over the place in my MVC app.
using(var tx = new TransactionScope()){
blah...
tx.Complete()
}
I'd like to make this DRYer somehow.
I've thought of a couple different options for this.
- An action filter to declaratively mark certain actions as transactional.
- Override OnActionExecuting in a Controller base class and make all actions transactional in one shot.
Are either of these a good idea? Any gotcha's I should look out for? The 2nd option seems like it might be a good way to get lots of deadlocks.
Oh yeah, I'm also using StructureMap and a custom controller factory to inject deps into my controllers in case someone knows of some tricks for injecting transactions that way.