WHAT IS ASP.Net MVC?
ASP.Net MVC is a Microsoft web application development framework, which is based on the popular MVC software pattern.
MVC stands for Model View Controller, and is a pattern, or a method of developing applications that strongly supports a number of other patterns, principles and best practices, including:
Separation of Concerns
Test Driven Development (or it’s most recent incarnation; Behavior Driven Development)
Domain Driven Development
Dependency Injection, and
Inversion of Control
To understand the MVC model you must understand the role of each of its three components.
Typical MVC Workflow
In an MVC application, all requests from a client are routed to a Controller class.
The Controller will then typically make a call to a service or some type of repository to retrieve data that will ultimately be sent to the client.
Any Services, Repositories or Entities accessed or manipulated by the Controller are collectively known as the Model.
Once the Model Entities have been retrieved by the Controller, they can be sent to the final part of the MVC jigsaw, the View.
The only responsibility of the View is to display any data sent to it by the Controller. This usually involves building the HTML structures and input controls that the user will interact with.
Ending the workflow, the View sends the resulting HTML to the response stream.
Figure 1.0 clearly shows the responsibilities of each component of the MVC model within a typical ASP.Net MVC application.
<<< INSERT FIGURE 1.0 HERE – DEPICTING THE RESPONSIBILITIES OF EACH PART OF A TYPICAL MVC ARCHITECTURE >>>
As Figure 1.0 shows, the MVC pattern supports the important concept of modularity and separation of concerns.
It implies that no business logic be mixed in with presentation logic, that the Controller be concerned only with passing data between the View and the Model, and that the Models’ only concern be the business domain and data.
As you’ll come to learn, when developing web applications using ASP.Net MVC, you are literally guided along a path of best practices, because the way the framework has been built makes it very easy to build modular, well tested code that’s extensible and easier to maintain, especially if that’s what you set out to accomplish.
ASP.Net Key Features
In October 2007, vice president at the time, Scott Guthrie, announced a new web development platform called MVC, which was built on the core ASP.Net platform.
The motivation for ASP.Net MVC was in response to technologies such as Ruby on Rails, which at the time overcame many of the pitfalls or restrictions of the ASP.Net Web Forms model at the time.
The MVC pattern isn’t new, it dates back to a Smalltalk project at Xerox in 1978, but is extremely popular today as a web development platform.
As you know, the web in its simplest form is made up of HTTP Requests, and Responses to those requests.
This fits in very nicely with the MVC pattern. The user makes a request after interacting with the UI, and in response, the application interacts with the model before delivering an updated view to the user.
When developing a web application, you generally have to combine several technologies such as HTML, DLLs & executables and data sources, which are generally split into multiple tiers. This basic principle is a natural fit for MVC methodology.
Extensibility
The ASP.Net MVC has a number of core components such as a Routing Engine, a Controller Factory and a View Engine.
The designers of the MVC framework have made these core components highly extensible by giving you three options:
You can use the default implementation, which is generally good enough for most situations
You can derive from a subclass of the default behaviour
Or, you can completely replace the component with a new implementation of the target interface
This is similar to overriding the Data Provider model in ASP.Net, but this follows right through to the core of the MVC framework.
You’ll learn more about the ASP.Net MVC framework extensibility model later in this article.
Testability
These days, more and more developers are getting used to the idea of unit testing their code.
This is probably due to the fact that tests tend to give you a sense of security in situations such as those nerve racking demos most of us have sat through.
If you’ve written unit tests for the important methods in your code, you
Write some crap about testability of the asp.net mvc framework