Monday, February 25, 2008

Making your own MVC - Naming problems

Things aren't working out the way I hoped or planned. But then again, when do they?

My migration code is still a spike, and has no tests. The controller-routing part works, and so does my views. They are WebForms, after all. But I have problems with the naming conventions, as ReSharper struggles with them. I don't know if that's a ReSharper bug or an inherent weakness in .NET.

The convention is to locate the view in a path like this: /views/controllername/viewname.aspx.

The problem arise when I have a controller an a model with similar name, like PlanController and Plan, and a view named like an existing class. The view to list plans would have a path like /Views/Plan/List.aspx.

You see how Visual Studio would create a WebForm class named List in a namespace named Views.Plan?

That creates some problems with ReSharper and .NET:
  • The namespace name Plan shadows the model of the same name. ReSharper intellisense stops at the namespace and never suggests to use the model class.
  • The compiler thinks I am using a namespace where a class is expected.
  • The view name List shadows the generic List class. ReSharper intellisense doesn't recognize this, and never suggests to use use List.
Even if the ReSharper intellisense was improved, there are problems with this approach that can't be fixed in an elegant way. The name crach between List.aspx and List will never go away, and suggests a problem with my naming.

The namespace/model crash can be fixed by prefixing the model class, but I don't like to litter my code with Models.Plan or whatever the model-namespace would be.

No comments: