Handling exceptions and rollbacks in MVC3 with NHibernate
I'm using a transaction-per-action filter in MVC3 like Ayende describes and wondered how others handle exce开发者_高级运维ptions and rollbacks.
The action filter will learn about an exception from the filterContext object, and will automatically rollback the transaction. But if I handle the exception in my action, then that doesn't happen.
I've thought of using HttpContext.Current.Items to stash a flag of some sort that the transaction failed, and then having my action filter check for it, but that's a kludge I'd prefer to avoid.
Can anyone offer me advice on this?
Sharp architecture provides IDbContext to do this.
On controller you can override OnResultExecuted for a safe area to dispose your context, or to rollback your transaction or whatever unit of work related.
精彩评论