Thunderdome 动作调用者 asp.net mvc
我知道雷霆穹顶原理的基本思想(一个对象进入,一个对象离开),但我没有在 ASP.NET MVC 中看到任何现实世界的例子。 这是雷霆穹顶原理的好例子吗
public ActionResult Index(Employee employee)
{
//some actions here
return View(employeeViewModel);
}
但是声明呢
控制器类永远不会 直接接触任何相关事物 到 HttpContext
操作调用程序应该是什么样子? 您能提供一些示例和单元测试吗?
“Thunderdome 原理” – 所有 Controller 方法都接受一个 ViewModel 对象(或在某些情况下零个对象)并返回单个 ViewModel 对象(一个对象进入,一个对象离开)。 控制器类永远不会直接暴露于与 HttpContext 相关的任何内容。 没有什么比看到人们试图编写模拟或存根新 IHttpContextWrapper 接口的测试更让我哭泣的了。 同样,Controller 方法不返回 ViewResult 对象,并且通常与所有 MVC 基础结构解耦。 我们很早就采用了这种策略,作为一种使控制器测试更简单的机械方法。
但我想知道该怎么做? 如何编写这样的控制器动作调用程序? 因为通常我们必须模拟 httpcontext
I know basic idea of thunderdome principle (one object enters, one object leaves) but I didn't see any real world example of it in asp.net mvc.
Is it good example of thunderdome principle
public ActionResult Index(Employee employee)
{
//some actions here
return View(employeeViewModel);
}
But what about statement
The Controller classes will NEVER be
directly exposed to anything related
to HttpContext
How the action invoker should looks like ? Could You provide some examples and unit tests for it ?
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.
But i want to know how to do this ? how to write such controller action invoker ? becouse normally we have to mock httpcontext
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Oxite rev2 源中有一个示例,说明如何在 ASP.NET MVC 中实现 OMIOMO (Thunderdome) 操作调用程序。
特别是 OxiteActionInvoker:
http://oxite.codeplex.com/SourceControl/changeset/view/31497# 442766
在这里您可以看到一个 OMIOMO 控制器:
http://oxite.codeplex.com/SourceControl/changeset/view/31497# 442745
同样有趣的是,Oxite 的人能够做到这一点,这样您就可以拥有支持 IoC 的操作过滤器(而不是必须在操作上指定所有过滤器 - 可能会违反 OCP,因为该操作会然后必须知道它的所有可能的使用方式)。 您可以在 OxiteActionInvoker 方法“GetFilters”中看到此操作,它会点击 FilterRegistry 来加载该操作的所有已注册过滤器。
There is an example of how to achieve a OMIOMO (Thunderdome) Action invoker in ASP.NET MVC in the Oxite rev2 source.
Specifically the OxiteActionInvoker:
http://oxite.codeplex.com/SourceControl/changeset/view/31497#442766
And here you can see a controller that's OMIOMO:
http://oxite.codeplex.com/SourceControl/changeset/view/31497#442745
Also of interest, the Oxite guys were able to make it so that you could you have IoC-able action filters (vs. having to specify all your filters on the actions -- a possible OCP violation since the action would then have to know all the possible ways in which it would be used). You can see this in action in the OxiteActionInvoker method "GetFilters" where it hits the FilterRegistry to load all the registered filters for that action.
这是 MVC 应用程序最干净的方法“雷霆穹顶原则(一个对象进入,一个对象离开)”。 您应该始终尝试以这种方式执行操作,并避免使用 ViewData 或 ViewTemp 以便在视图中获取必要的数据。
对于一个简单的示例,您可以在此处查看 jscportal 项目 链接文本
例如在
jscportal\ JSC.Portal.Web\Controllers\TemplatesController.cs
你会得到他们想要的例子:
祝你好运!
This is the most clean approach "thunderdome principle (one object enters, one object leaves)" for MVC applications. You should always try to do trhings in this style, and avoid using ViewData or ViewTemp in order to get your necessary data in the view.
For a simple example you can look in the jscportal project here link text
for example in the
jscportal\JSC.Portal.Web\Controllers\TemplatesController.cs
you'll have their examples like you want:
good luck!