ASP.NET MVC Framework – Overview

ASP.NET Model View Controller Framework is a new model used in developing ASP.NET applications as opposed to the traditional Web forms model. It comes as a part of ASP.NET 3.5 Extensions. MVC is a methodology that divides application framework into three component roles: Models, Views, Controllers.

Models:
Models are Components of application that maintains the state, often persisted inside a Database. Model objects are part of application that implement logic for the application’s Data domain. Model objects retrieve and store model state in database. In small applications, Model is just a conceptual separation than a physical one. If an application only reads a dataset and sends it to a view, it does not have a physical model layer and associated classes. In that case, Dataset takes the role of a Model object.

Views:
Views are Components responsible for maintaining the application user interface, which is created based on the Model data. The view only displays information.

Controllers:
Controllers are Components responsible for handling end user interaction, manipulating the model and ultimately choosing a view to render to display UI. It lives for a single http request and goes away. For instance, the Controller handles query strings and passes these values to the model, which in turn queries the database by using the values.

Contract in M-V-C
The MVC pattern helps us to create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should exist in the application. Each page is split into Controller and View that operates on same Model of data. MVC Framework is defined in System.Web.MVC namespace.

Handles Complexity
The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. There is a clean separation of concerns between Models, Views and Controllers within application. This separation helps us manage complexity when building an application, because it enables us to focus on one aspect of the implementation at a time.

Parallel Development
The loose coupling between the three main components of an MVC application also promotes parallel development. For instance, one developer can work on the view, a second developer can work on the controller logic, and a third developer can focus on the business logic in the model.

Test driven Development
All core contracts within the MVC framework are interface-based and can be tested by using mock objects, which are simulated objects that imitate the behavior of actual objects in the application. We can unit-test the application without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible. We can use any unit-testing framework that is compatible with the .NET Framework. Automated unit tests can be implemented which define and verify the requirements of new code before writing the code itself.

Extensibility
MVC is an extensible and pluggable framework. The components of the ASP.NET MVC framework are designed so that they can be easily replaced or customized. We can plug in our own view engine, URL routing policy, action-method parameter serialization, and other components. MVC supports static and dynamic languages.

PostBack and Viewstate
Views no longer use Postback or ViewState. This makes the MVC framework ideal for developers who want full control over the behavior of an application. Post back and Viewstate model employed by Webforms have caused pains, because they employ an elaborate scheme to hide the developer from stateless nature of HTTP. With event handlers and the page lifecycle, the developer falls into managing state with ViewState and Postbacks, and when employed in the reality of the stateless Web, the model becomes fragile and has problems scaling with complexity.

Architectural Styles and Design Patterns
Dependency Injection (DI) allows us to inject objects into a class, rather than relying on the class to create the object itself. IOC (Inversion of Control) specifies that if an object requires another object, the first objects should get the second object from an outside source such as a configuration file. MVC Framework supports both DI and IOC. This is useful in Test driven development. MVC uses a Front Controller pattern that processes Web application requests through a single controller. This enables us design an application that supports a rich routing infrastructure

Compliance with ASP.NET features
MVC Framework offers support for using the markup in existing ASP.NET page (.aspx files), user control (.ascx files), and master page (.master files) markup files as view templates. We can use existing features such as nested master pages, in-line expressions (), declarative server controls, templates, data-binding, localization, forms and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, configuration system, the provider architecture etc.

URL:
MVC Framework does not consider URL as an endpoint to the physical server file (ASPX) to parse and compile to a class. It neither includes file-name extensions nor maps to files stored in the disk. Instead it is seen as the means to address a logical server resource. MVC employs a centralized http hander that recognizes an application specific syntax for links. Each addressable resource exposes a well-known set of operations and a uniform interface for executing operations. The requested action is codified in the URL according to the application-specific syntax. HTTP handler analyzes the syntax of the URL and invokes the action on the controller and the controller will process the request up to generating the response in whatever response format we need. The response is generated through a view component.  

URL Mapping
URLs are designed to support URL naming patterns that work well for search engine optimization (SEO) and representational state transfer (REST) addressing. The ASP.NET MVC framework incorporates a URL-mapping engine that provides flexibility for mapping URLs to controller classes. We can use the mapping engine to define routing rules that the ASP.NET MVC framework uses to evaluate incoming URLs and to select a controller to execute. We can also have the routing engine automatically parse variables defined in the URL and have the ASP.NET MVC framework pass these to the controller as parameter arguments.

REST
Representational State transfer (REST) is an architectural pattern that defines how network resources should be defined and addressed in order to gain shorter response times, clear separation of concerns between the front-end and back-end of a networked system. REST is based on three following principles: 1. An application expresses its state and implements its functionality by acting on logical resources 2. Each resource is addressed using a specific URL syntax 3. All addressable resources feature a contracted set of operations

REST in MVC
MVC uses a REST-like approach to ASP.NET Web development. It implements each request to the Web server as an HTTP call to something that can be logically described as a “remote service endpoint”. The target URL contains all that is needed to identify the controller that will process the request up to generating the response–whatever response format we need.”

References:
http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx
http://dotnetslackers.com/articles/aspnet/AnArchitecturalViewOfTheASPNETMVCFramework.aspx
http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx
http://aspalliance.com/1562_Implementing_the_MVC_Design_Pattern_in_ASPNET