如何实现在MVC工作单位:责任 [英] How to implement Unit of work in MVC: Responsibility

查看:117
本文介绍了如何实现在MVC工作单位:责任的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁有人的职责

谁都有责任开始和完成工作的单位在MVC架构?

Who has the responsibility to start and finish the Unit of work in a MVC architecture?

推荐答案

这不是一个控制器的责任,它违反了 SRP 。控制器甚至不应该知道的UOW的。在网上,每个请求对应一个UOW到服务器通常使用。在这种情况下,UOW应在一个请求结束被设置并启动某处的请求的开始后(理想启动UOW的应懒惰)。要做到这一点,最好的地方是使用Application_EndRequest和的Application_BeginRequest处理Global.asax中(或您的HttpApplication类)。结果
这可以通过IOC框架可以轻松实现(我最喜欢的是温莎),请参阅
this问题了解实施细节。

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工作单位:责任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆