I've been playing with ASP.NET MVC 3 some days now and I have some thoughts about it. First of all, it looks cool, using the Razor syntax in views is already a step in the good direction. But, why on earth do we need Dependency Injection in an MVC framework? DI is cool in enterprise wide applications that need flexible interfaces and thorough testing, but use it in MVC? I think we forget the essence of what a MVC framework should do: display information. No calculations, no fancy techy obscure coding, no, just fetch the data for your view model, do some simple logic for display and input handling and create views for that. Want calculations? -> Use services. Want heavy techy stuff? -> Use services. That is the reason we came up with SOA no?
I my opinion a website should have a very small footprint in your business process. It should be easily maintainable and very transparent to non developers like content managers, designers and marketeers. You could say that a good website should have at least some kind of CMS right? Maybe that is true, but still, transparency is the key to success. It helps you tune you site once it slows down, scale your site if it grows, ...
If you start using DI you don't know where it ends. MVC is not only a cool framework because you have control over how you would like your views to look, it also offers you a very testable base that allows you to test controllers and views in a simple transparent way.
The same goes for the new Razor syntax which is nice and well thought, we all work qwerty right, where the @ is better reachable then our worshipped %. But that is another story. Let’s take a small example of some old MVC code and the new Razor syntax
ASP.NET MVC syntax
1: <ul>
2: <% 1: foreach(var p in Model.Products) { %>
3: <li><% 1: = p.Name
%> ($<% 1: = p.Price
%>)</li>
4: <% 1: }
%>
5: </ul>
Razor syntax
1: <ul>
2: @foreach(var p in Model.Products) {
3: <li>@p.Name ($@p.Price)</li>
4: }
5: </ul>
In both cases if we open these files in an editor that is not Visual Studio, we end up with some nasty code in our design that isn’t supposed to be there. Why not surround all logic tags by <!---->, yes, the HTML comment tags.
Suggestion
1: <ul>
2: <!--@foreach(var p in Model.Products) {-->
3: <li>@p.Name ($@p.Price)</li>
4: <!--}-->
5: </ul>
It solves some issues with our designers I think.
Maybe I will be back with some more thoughts about it. My credo still remains the same keep it simple ;)
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Featured, Development
c# mvc