I am totally in love with ASP.Net MVC 2 so I figured what better topic for my first post.
When I first saw the presentations on MVC (or if you prefer MVVM), I wasn't impresesed. My first reaction is "I already do that." I looked at it as a design pattern, seperation of concerns, etc. Then I watched Scott Hanselman's video and realized two very important things:
- MVC is not web forms
- MVC 2 ships with VS 2010 (even Express)
The second is possibly the most important. I had looked at other Microsoft patterns (Enterprise Library, etc.) and in general they were overly bloated and forced you to a VERY specific design pattern which was not necessarily compatible with other things you were doing. In some cases, MVC is the same - you won't be able to just start making MVC "stuff" and sticking it in your existing web forms app.
Another problem with previous patterns was you had to make sure that everyone on your team had the same release. While there are updates to MVC, only one version ships with VS so unless you do something out of the ordinary you will be on vanilla MVC 2.
So why do I love MVC (today)? Well, after watching Scott's video and playing around on my own, I was enjoying not having to cast query string parameters to their native types. I wrote methods that looked something like this:
public ActionResult SomeMethod(int? id, string someParam, string someOtherParam)
MyModel model = new MyModel()
Id = id,
SomeProperty = someParam,
SomeOtherProperty = someOtherParam
All was right with the world. I had a model that contained everything I needed and in many cases was a class already created based on a prior encarnation of the application.
Then I started getting 20-30 parameters in my methods and things started getting ugly. Then I had my MVC epiphany of the day: MVC model updates can happen via both POST and GET! So the method above (which was really ugly) turned into this:
public ActionResult SomeMethod()
MyModel model = new MyModel();
Ahh! So elegant it hurts!