我应该使用try-catch块(旨在捕获/处理StaleObjectStateException)将对存储库的调用包装在ASP.NET MVC应用程序的相应控制器中,还是应该在存储库实现中进行?
另外,我如何处理异常,通知用户。据我所知,没有回滚的意图?
谢谢!
发布于 2012-02-25 02:41:05
问题归结为一个不同的问题:在哪里以及如何处理实体的并发修改?也就是说:用户A和用户B编辑相同的记录,当稍后保存该记录的用户(用户B)获得StaleObjectStateException时,因为他编辑的版本现在已过期。
以下是一些想法:
- Inform the user that the record couldn't be saved due to concurrent changes by another user and throw all changes away, forcing him to do everything from scratch. This is of course painful for the user and should only be done if this really occurs rarely.
- Inform the user about the issue and let him decide what to do, e.g. force his changes or start over.
虽然这超出了你的问题,但我希望这仍然对你有帮助。
发布于 2012-02-24 22:40:35
如果您正确使用DI,那么将这种异常管理放在控制器中将打破您的关注点分离。
控制器属于表示层,表示层并不知道您正在使用什么来存储数据,而StaleObjectStateException是NHibernate之类的东西。
https://stackoverflow.com/questions/9431656
复制相似问题