Tuesday, April 26, 2011

MVC View lookup

I am working on ASP.Net MVC these days and generally loving it. It is designed to be extensible and it seems like it needs it.

My current requirement is to be able to include parameters other than controller name and view name into the ViewEngine lookup mechanism. This lead me to look at the existing ViewEngine implementations and to come to the conclusion that they are poorly decomposed.

The existing design has two ViewEngines registered one for Webforms and one for Razor. The actions of these two ViewEngines is to look in the same directories but for different files. There is obviously some duplication of effort in this scheme which would be made worse if the website used other IView implementations. I think that the problem here assumes that the IView is considered the more important decomposition than the source of the views which is the Virtual File System. This maybe true for a large majority of websites that use a single IView implementation but not if multiple IView implementations are in use.

It there was a single VirtualFileViewEngine it could search the file system looking for files that matched the view and controller name. Then as a second step it could select an IView Implementation based on the file extension. This would make supporting additional IView implementations like xslt or Spark trivial. It also would solve the issue documented at http://blogs.msdn.com/b/marcinon.

It would not break any existing extension points it would just be adding an alternative extension point. Developers can still register alternative ViewEngines but if they are happy with the default locations of files they can just register and IView implementation for a file extension.

This does not actually solve my problem (which is to search additional directories based on other context) but is does localize the changes I need to make a little more closely.

Labels:

0 Comments:

Post a Comment

<< Home