NHIbernate IHttpModule 和 TransactionScope
只是想知道其他人对在 IHttpModule 中使用 TransactionScope 有何想法。 例如:
BeginRequest
//start new TransactionScope
// start UOW
// Begin UOW transaction
// do some stuff...
EndRequest:
// commit UOW
// commit transaction scope
在 http 请求的生命周期中保持 transactionscope 开放真的是一个明智的想法吗? 我需要同时写入事务性 MSMQ 并且需要 TransactionScope。我希望持久保存数据库更新并发送 MSMQ 消息,否则将其全部回滚...
有什么建议吗?
Just wondering what other's thoughts are on using a TransactionScope in an IHttpModule.
For example:
BeginRequest
//start new TransactionScope
// start UOW
// Begin UOW transaction
// do some stuff...
EndRequest:
// commit UOW
// commit transaction scope
Is it really a wise idea to hold the transactionscope open for the life of a http request?
I need to write to transactional MSMQ at the same time and have the need for the TransactionScope. I'd like db updates to be persisted as well as MSMQ messages to be sent, or else, roll it all back...
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会随机失败,因为在 ASP.NET 中,不能保证 BeginRequest 和 EndRequest 将发生在同一线程上(又名
有关更多详细信息:
http ://www.mattwrock.com/post/2010/12/26/Getting-TransactionScope-to-play-nice-with-NHibernate.aspx
This would fail randomly because in ASP.NET there is no guarantee that BeginRequest and EndRequest will occur on the same thread (aka thread-agility). A Transaction scope will throw an exception if you try to dispose of it on a different thread than the one where it was created. So in the occasional event that EndRequest executed on a different thread then BeginRequest, this exception was thrown.
For more detail:
http://www.mattwrock.com/post/2010/12/26/Getting-TransactionScope-to-play-nice-with-NHibernate.aspx