Thunderdome MVC-为什么一个模型在MVC? [英] Thunderdome MVC- Why one-model-in in MVC?

查看:93
本文介绍了Thunderdome MVC-为什么一个模型在MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当杰里米&放大器;乍得<一个href=\"http://$c$cbetter.com/blogs/jeremy.miller/archive/2008/10/23/our-opinions-on-the-asp-net-mvc-introducing-the-thunderdome-principle.aspx\">posted他们FubuMvc项目,他们提到的差异化之一是他们的Thunderdome校长:

When Jeremy & Chad posted about their FubuMvc project, one of the differentiators they mentioned was their "Thunderdome Principal":

在Thunderdome原理 - 所有
  控制器方法采取在一个
  视图模型对象(或在零对象
  某些情况下),并返回一个
  视图模型对象(一个对象进入
  一个对象离开)。控制器
  类永远不会直接暴露
  于与HttpContext的任何东西。
  没有什么让我哭就像看到
  人们试图写模拟测试
  或存根新IHttpContextWrapper
  接口。同样,控制器
  方法不返回的ViewResult
  对象,并且通常解耦
  所有MVC架构。我们
  采取这种策略很早就为
  一种方法,使控制器测试
  简单机械。这绝对
  实现了这一目标,但它也取得了
  控制器code非常精简
  并且容易阅读。我们将解释如何
  这个工作在KaizenConf。

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.

什么是他们的一视图模型(或零)的方法呢?

What is the advantage of their 'one ViewModel (or zero) in' approach?

推荐答案

它的主要优点是,它是一个约定,使事情在我们所有的控制器是一致的。它使我们更容易建立测试上下文/夹具,可以在集成测试场景初始化环境。在大多数情况下,约定==快速性,因为它从你的设计考虑去掉了很多假设场景。

Its primary benefit is that it's a convention and makes things consistent across all our controllers. It makes it easier for us to set up testing "contexts"/fixtures that can initialize the environment in an integration testing scenario. In most cases, Conventions == Rapidity as it removes a lot of "what if" scenarios from your design considerations.

由于我们所有的控制器行为遵循相同的模式,我们可以假设很多东西,它加速并简化我们的控制器集成测试工作。

Since all our controller actions follow the same pattern, we can assume many things and it accelerates and streamlines our controller integrated testing efforts.

有什么不对的,一定是与具有多个参数到一个控制器动作,但我们发现,有一个实际的模型对象为我们提供了一些额外的功能,因为该模型可以包含简单的逻辑和揭露的便利性这可以简单一些比较自己的状态等复杂的方面 - 基本上,这是任何有丰富的模型参数,而不是唯一的Thunderdome / OMIOMO模式

There's nothing wrong, necessarily, with having multiple arguments to a controller action, but we found that having an actual model object affords us some extra functionality since the model can contain simple logic and expose convenience properties which can simply some of the more complex aspects of its own state, etc -- basically, this is the argument for having any rich model and isn't unique to the Thunderdome/OMIOMO pattern.

这篇关于Thunderdome MVC-为什么一个模型在MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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