asp.net-mvccontrollerfubumvc

thunderdome action invoker asp.net mvc


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 ?


from http://codebetter.com/blogs/jeremy.miller/archive/2008/10/23/our-opinions-on-the-asp-net-mvc-introducing-the-thunderdome-principle.aspx

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


Solution

  • 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.