谁有责任
谁有责任在MVC架构中启动和完成工作单元?
解决方法
它不是控制器的责任,它违反了
SRP.控制器根本不应该知道UoW.在Web中,通常使用每个服务器请求一个UoW.在这种情况下,UoW应该在请求结束时处理,并在请求开始后的某个地方启动(理想情况下,UoW的启动应该是惰性的).执行此操作的最佳位置是使用Application_EndRequest和Application_BeginRequest处理程序的Global.asax(或您的HttpApplication类).
这可以通过IOC框架轻松实现(我最喜欢的是Windsor),请参阅 this question了解实现细节.
这可以通过IOC框架轻松实现(我最喜欢的是Windsor),请参阅 this question了解实现细节.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。