Wednesday, November 27

ASP.NET MVC 4

ASP.NET MVC


      The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating MVC-based Web applications. The MVC framework is defined in theSystem.Web.Mvc namespace and is a fundamental, supported part of the System.Web namespace.   It is integrated with existing ASP.NET features, such as master pages and membership-based authentication.
 The MVC framework includes the following components:
Description: Invoking a controller action that expects a parameter value

## ASP.NET MVC is open source !-##
 In March 2012, Scott Guthrie announced on his blog that Microsoft had released part of their web stack (including ASP.NET MVC, Razor and Web API) under an open source license (Apache License 2.0).
-Download from Codeplex.com

## ASP.NET MVC is a web application development framework built on top of Microsoft’s .NET Framework. ASP.NET Web Form was a replacement for Microsoft’s Active Server Pages (ASP) but ASP.NET MVC is not a replacement for ASP.NET Web Forms and it’s just an alternate way of making an ASP.NET website.

The MVC pattern helps you 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 be located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic. 


Advantages of an MVC-Based Web Application

The ASP.NET MVC framework offers the following advantages:
·       It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
·       It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
·       It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure. For more information, seeFront Controller on the MSDN Web site.
·       It provides better support for test-driven development (TDD).
·       It works well for Web applications that are supported by large teams of developers and Web designers who need a high degree of control over the application behavior.

Advantages of a Web Forms-Based Web Application

The Web Forms-based framework offers the following advantages:
·       It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls.
·       It uses a Page Controller pattern that adds functionality to individual pages. For more information, see Page Controller on the MSDN Web site.
·       It uses view state or server-based forms, which can make managing state information easier.
·       It works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development.
·       In general, it is less complex for application development, because the components (the Page class, controls, and so on) are tightly integrated and usually require less code than the MVC model.



Front Controller:
http://msdn.microsoft.com/en-us/library/ms978723.aspx

Context:

 You have decided to use the Model-View-Controller(MVC) pattern to separate the user interface logic from the business logic of your dynamic Web application. You have reviewed the Page Controller pattern, but your page controller classes have complicated logic, are part of a deep inheritance hierarchy, or your application determines the navigation between pages dynamically based on configurable rules.

Problem :

How do you best structure the controller for very complex Web applications so that you can achieve reuse and flexibility while avoiding code duplication?.


Page Controller
http://msdn.microsoft.com/en-us/library/ms978764.aspx

Context

You decided to use the Model-View-Controller (MVC) pattern to separate the user interface components of your dynamic Web application from the business logic. The application you are building constructs the Web pages dynamically, but the navigation between the pages is mostly static.

Problem

How do you best structure the controller for moderately complex Web applications so that you can achieve reuse and flexibility while avoiding code duplication?

Solution

Front Controller solves the decentralization problem present in Page Controller by channeling all requests through a single controller. The controller itself is usually implemented in two parts: a handler and a hierarchy of commands (see Figure 1).

Figure 1: Front Controller structure
Description: C:\Users\Hibrise\Desktop\IC31317_mvc kareem1.gif
The handler has two responsibilities:
·  Retrieve parameters. The handler receives the HTTP Post or Get request from the Web server and retrieves relevant parameters from the request.
·  Select commands. The handler uses the parameters from the request first to choose the correct command and then to transfers control to the command for processing.
Figure 2 shows these two responsibilities.
Description: C:\Users\Hibrise\Desktop\IC79927 mvc kareem2.gif
Figure 2: Front Controller, typical scenario
The commands themselves are also part of the controller. The commands represent the specific actions as described in the Command pattern [Gamma95]. Representing commands as individual objects allows the controller to interact with all commands in a generic way, as opposed to invoking specific methods on a common command class. After the command object completes the action, the command chooses which view to use to render the page.


No comments:

Post a Comment