开发者

Handling exceptions and rollbacks in MVC3 with NHibernate

开发者 https://www.devze.com 2023-02-27 19:46 出处:网络
I\'m using a transaction-per-action filter in MVC3 like Ayende describes and wondered how others handle exce开发者_高级运维ptions and rollbacks.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消