问题描述
谁有人的职责
谁都有责任开始和完成工作的单位在MVC架构?
Who has the responsibility to start and finish the Unit of work in a MVC architecture?
推荐答案
这不是一个控制器的责任,它违反了了解实施细节。
It's not a responsibility of a controller, it violates SRP. Controller should not even know about UoW at all. In web, one UoW per request to server is usually used. In this case UoW should be disposed at the end of a request and started somewhere after the beginning of a request (ideally start of a UoW should be lazy). The best place to do this is Global.asax (or your HttpApplication class) using Application_EndRequest and Application_BeginRequest handlers.
This can be easily achieved with an IOC framework (my favorite is Windsor), see this question for implementation details.
这篇关于如何实现在MVC工作单位:责任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!