1

Is it possible to commit a transaction in the background while already returning the view to the user when using nHibernate in an ASP.NET MVC application?

So upon reaching "ActionExecuted", which is normally the point at which the transaction is committed when using the session-per-request pattern, I want to continue right away while nHibernate starts committing. This would allow the user to see the resulting view earlier.

4

1 回答 1

0

与其在后台提交(你可以使用线程来做,只要你确保会话之后被清理),为什么不切换到基于队列的架构呢?

优点:

  • 它实际上是为您想要的而设计的,而不是 hack
  • 您可以根据需要向外扩展(相同的应用程序、不同的应用程序、不同的服务器、不同的数据中心......)
  • 如果您正确构建它,它可以提供比直接到数据库的方法更高的可靠性

当然,有一个成本,即为队列创建 DTO,然后构建实际事务。而且,当您将控制权返回给用户时,请求并没有真正完成(这是不确定的。下一个请求可能会在数据库中找到数据)

于 2013-06-20T03:34:08.547 回答