ASP.NET 3.5 - MVC Design: A Front Controller based Approach

          

ASP.NET 3.5 MVC Design: A Front Controller based Approach


<<Previous  Next>>
Model view controller
Page controller pattern
MVC design
REST architecture
MVC framework


ASP.NET 3.5 Application Architecture and Design

This excerpt from ASP.NET 3.5 Application Architecture and Design by Thiru Thangarathinam, is printed with permission from Packt Publishing, Copyright 2007.

MVC Design introduction
Front Controller Design
Basics of MVC

MVC Design: A Front Controller based Approach

MVC, which stands for Model View Controller, is a design pattern that helps us achieve the decoupling of data access and business logic from the presentation code , and also gives us the opportunity to unit test the GUI effectively and neatly, without worrying about GUI changes at all. In this section, we will fi rst study the basic MVC pattern and then move on to understanding the ASP.NET MVC framework.

Front Controller Design

MVC is based on a front controller design, where we have a centralized controller instead of multiple controllers, as was the case in the page controller based design that we saw earlier. By default, ASP.NET is page controller based. So making a front controller based project would require a lot of work (using HttpHandlers to route the requests manually). Basically, in a front controller design, we trap all of the client requests and direct them to a central controller, and the controller then decides which view to render (or which ASPX page to process). Here is how a basic model of a front controller design works:

Front Controller Design

As you can see, the front controller sits at the "front" of all of the pages and renders a view based on logic in the central controller fi le. In the next section we will study and analyze exactly what goes on inside a controller, a view, and a model.

Basics of MVC

Let's fi rst get into the theoretical aspects of MVC. MVC design has three major parts:

  • Model: This refers to the data that is shown in the UI. This data can come from different sources, for example, a database.
  • View: This refers to the user interface (UI) components that will show the model data.
  • Controller: This controls when to change the view, based on user actions, such as button clicks.

In terms of ASP.NET web applications, the model, view, and controller participants can be identifi ed as:

  • View: This refers to HTML markup in ASPX pages, minus the code-behind logic. This view is rendered in the presentation tier (the browser).
  • Controller: This refers to the special controller classes that decide which model needs to be shown to which particular view.
  • Model: This refers to the data coming from the data layer, which may be processed by the business layer.

Before moving ahead, an important point to understand is that the MVC design is not a replacement to the n-tier architecture. MVC is more focused on how to keep the UI separate from the logic and the model; the model itself can be broken into separate tiers.

In the MVC design, the model, the view, and the controller are not related directly to the layers, or to the physical tiers; they are logical components that operate together in a certain pattern. The controller is related directly to the model and the view. Based on user actions (in the view), it fetches the data (the model) and populates the view. The relationship between the controller, the model, and the view can be depicted as:

Basics of MVC

The view is based on the model, which means that its job is to simply render the model that the controller passes to it:

MVC

So the net relationship between the three components can be described as:

MVC

A few important points to note from the above diagram:

  • We can see that the model depends neither on the view nor on the controller, which is logical. Think of it like this: we have some data in the database tables; we use DAL code to handle this data and BL code to operate on this data as per certain business rules. Now, it is up to the UI to present and show this data. But the data itself is not dependent on the graphical user interface (GUI). So the model is independent of the view and the controller.
  • The view does not depend on the controller; rather, the controller is associated with the view. That means we have a separation between the view and the controller, allowing us to change views independent of the controller.
  • The view depends on the model, and is updated when the model's state has changed. As the view cannot contain any logic (which is stored inside the model), the view depends on the model; that is, the model is in charge of updating the contents or displaying the view.

Now we will look at the practical aspects of implementing this MVC design using the ASP.NET MVC framework, which will help us implement our web applications. MVC will be ready in no time. But before going ahead with the actual code, we need to understand another important aspect of ASP.NET MVC framework, that is, REST!

<<Previous  Next>>



Write your comment - Share Knowledge and Experience


More Related links   

What Is ASP.NET MVC?

The ASP.NET MVC framework was created to support pattern-based software development. In other words, the framework was designed to make it easier to implement software design principles and patterns when building web applications..............

.NET Assembly Interview questions with answers
Define .Net Assembly. | What does an assembly contain? | Define a private assembly and a shared assembly. | What are Satellite Assemblies? | What do you understand by side-by-site execution of assembly? | How do you create a resource-only assembly? | Explain how to retrieve resources using ResourceManager class. | Define Strong Name. | How do you apply a strong name to assembly? | Define Global Assembly Cache. | How do you install assembly to the Global Assembly Cache?

ASP.NET Authentication Authorization Questions with answers
Define Authentication and Authorization | What is the authentication mode available in ASP.NET? | How do you set authentication mode in the ASP.NET application? | List out the difference between windows authentication and form authentication | How do you impersonate the authenticated user in ASP.NET? | How do you provide secured communication in ASP.NET?
Interview questions and answers on .Net web service
What is XML Web Server? | Describe the Components that help locate and consume XML Web Service. | Describe the process of communication between Client and Web Service. | What are the components published while deploying of Web Service? | Describe .disco file. | Describe the step to be followed to access web service by client.
.NET crystal reports

How do we access crystal reports in .NET?
What are the various components in crystal reports?
What basic steps are needed to display a simple report in crystal?..........

ASP.NET 2.0 Data Controls

One of the important goals of ASP.NET 2.0 is 70% code reduction. The data controls supplied with ASP.NET 2.0 play an important role in making this ambitious goal a reality. Data source controls provide a consistent and extensible method for declaratively accessing data from web pages..............

 

Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring