I found out the other day (the hard way) that ComponentController - my beloved little prototype - was ripped mercilessly from the MVC framework in Preview 4 and cast into the Pit Of Carkoon to "be slowly digested over thousands of years". I was mortified, vaklempt, the refactor dingo ate my baby! Incensed, I emailed that Eilon guy and said "you better run before I WTFPWN!" and he casually said "relax you little drama queen. I do what I always do... made your cruft shine". And so he did...
The Debate
We had a good thread going (among others) on the forums for a while about reusable controls and one of the ideas brought up by tgmbdm was to use something like "RenderAction" - wherein you render an Action to a page in a specific location. It's something that the Phil's team was working on for a while - and I brought this idea up to them and they said "yah - definitely want to do something like that. You do it".
So I prototyped up the ComponentController and it did what it was supposed to do - but kind of languished for a bit (for so long as a matter of fact that Phil forgot it was in there).
The issue that inevitably came up was "is this MVC?". Meaning - should a View be able to call a Controller's action? I'm going to sidestep that question because, well, encapsulating logic is needed.
The Code
In the MVC Storefront I had a nice ComponentController which output the category nagivation list on the left side of the screen. It worked nicely, and I could inject it with the right dependencies using StructureMap. The thing I couldn't do, however, was test it since ComponentController didn't implement an interface or base class. This was by design - there were some gymnastics I had to do to get the thing to render properly and... well I'll just leave it at that.
With the recent changes to Preview 4, I was able to completely remove the whole mess from the application and simply add an Action to the CategoryController:
public ActionResult CategoryList()
{
return View("_CategoryList", _catalogService.GetCategories());
}
Notice I use a "_" to denote a partial view - this is a convention used by a lot of view engines and so I'm keeping with it. To use it in a page, I can now simply:
<%Html.RenderAction<CatalogController>(x=>x.CategoryList()) %>
Radical. This has so many nice implications to it and I think it's one of the coolest new features of Preview 4. Aside from all that Ajax grooviness!
