Monday, April 14, 2008

I've just been having a frustrating time attempting to use the new HtmlHelper extension method in the MVC Framework CTP2, RenderComponent. There are so many problems with it that it's really not at all ready for any serious use. Here's a thread on the MVC forum dedicated to some of it's shortcomings:

The first thing to notice is that the RenderView method isn't virtual which means you can't mock it. I got around it with some horrible hackery. I defined an intermediate base class that my controller components use and I've hidden the RenderView method with a new virtual method.

The next thing is that the RenderView code is hard coded to use aspx view pages rather than using the configured view engine. I'm using the aspx view engine anyway, so it's not a killer for me, but even so it's very disappointing to see this.

Lastly, something which I do care about is the lack of a ComponentControllerFactory to allow us to substitute an alternative way of creating components. I am using the Windsor IoC container in my project and I would expect the RenderComponent method to call out to an abstract factory which would allow me to provide the components from Windsor. Luckily for me Jeremy Skinner has provided an alternative RenderComponent method in MVC contrib called RenderComponent2 which does just that. All I needed to do was register my Windsor container with his ComponentControllerBuilder: