Sunday, August 31, 2008

ASP.NET MVC Diary #2 WHAT?

Second, WHAT is the ASP.NET MVC framework?

Before diving into Microsoft's MVC, I decided to do a refresher recap of what the Model-View-Controller Design Pattern is. The design pattern was created to implement the separation of concerns by creating three tiers: Model, View, and Controller. More recently, the Model View Presenter pattern was released as an alteration of the MVC. The MVP's Presenter does more delegations to the view.

What is Model View Controller?
Model - The Model's responsiblity is to maintain state. A typical use for the Model is querying a database and and storing that data in a DTO (Data Transfer Object). The intent here is that the datasource can change and the conroller or view will still work as originally designed. The controller should not be aware of where the data came from or it's from LINQ, XML, or File.

View - The View's responsiblity is to present the information. This is typically done in the user interface. One example of a view would be Edit Customer.

Controller - The Controller is the glue that handles all of the interactions between the user interface (View) and the model. It does most of the heavy lifting by responding to a user interaction and manipulating the model. The view should only display information and does not care about the event handling. The controller also select which view to display based on the type of interaction.

What is REST?
REST - After reasearching ASP.NET MVC, I discovered that indeed it implements this pattern, but it also implements the Representational State Transfer (REST) architecture design as well. MVC uses a REST type archecture for it's routing mechanism. I needed to learn more about REST before going any further into my research. After learning more about REST, I trumpet this softly when I say this feature is one of the most compelling components of the ASP.NET MVC Framework.
Scott Gu's link below does an awesome job of detailing this routing system. Again, all of this is built into the framework so implement REST is quite easier than you think.

How is this different from Web Forms?
Web Forms use the Post Back model. MVC uses the framework's components along with routing architecture. Here is a diagram of how ASP.NET MVC works.

Simplified
















More Detailed












What is required to start developing?
Prerequisites - I have to admit, at first I thought it would be some libraries I would have to download and then just add them as references. IMHO, I feel like Microsoft has done a great job so far wrapping the required libraries and you will need to add a new project type 'MVC Web Project'. Here is what is required to start work:

Here is what I am using: Visual Studio 2008 with .NET 3.5 Framework, download ASP.NET MVC from Codeplex CTP release 4. Preview 5 was release August 28th.

References used:
Content based on research on the following sites:
MS Main MVC Page

Scott GU - REST

Phil Haack's: MVC History Lesson

Scott Hanselman's Walkthrough Video

Scott Gu

Dino Esposito on DotNetSlackers

Code Plex Download: MVC

0 comments: