加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Thunderdome MVC-为什么在MVC中使用one-model-in

发布时间:2020-12-16 04:29:03 所属栏目:asp.Net 来源:网络整理
导读:当杰里米 Chad posted about their FubuMvc project,他们提到的区别之一是他们的“Thunderdome Principal”: The “Thunderdome Principle” – All Controller methods take in one ViewModel object (or zero objects in some cases) and return a single
当杰里米& Chad posted about their FubuMvc project,他们提到的区别之一是他们的“Thunderdome Principal”:

The “Thunderdome Principle” – All
Controller methods take in one
ViewModel object (or zero objects in
some cases) and return a single
ViewModel object (one object enters,
one object leaves). The Controller
classes will NEVER be directly exposed
to anything related to HttpContext.
Nothing makes me cry like seeing
people trying to write tests that mock
or stub that new IHttpContextWrapper
interface. Likewise,Controller
methods do not return ViewResult
objects and are generally decoupled
from all MVC infrastructure. We
adopted this strategy very early on as
a way to make Controller testing
simpler mechanically. It’s definitely
achieved that goal,but it’s also made
the Controller code very streamlined
and easy to read. We’ll explain how
this works at KaizenConf.

他们的’一个ViewModel(或零)’方法有什么优势?

解决方法

它的主要好处是它是一种惯例,并使我们所有控制器的内容保持一致.它使我们更容易设置可以在集成测试场景中初始化环境的测试“上下文”/夹具.在大多数情况下,约定==快速,因为它从您的设计考虑中删除了很多“假设”场景.

由于我们所有的控制器操作都遵循相同的模式,因此我们可以假设很多事情并加速并简化我们的控制器集成测试工作.

有一个控制器动作有多个参数,没有什么不对,但我们发现有一个实际的模型对象为我们提供了一些额外的功能,因为模型可以包含简单的逻辑并暴露方便的属性,这可能只是一些更复杂的方面.它自己的状态等 – 基本上,这是拥有任何丰富模型的论据,并不是Thunderdome / OMIOMO模式所独有的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读