Wednesday 21 January 2015

MVC Request Life Cycle

Asp.Net MVC life cycle steps are as follows

1.Routing
2.MVCHandler
3.Controller
4.Action Execution
5.ViewResult
6.View Engine
7.View


Routing: Request go to the  Global.asax file of the application

protected void Application_Start()
        {
                       RouteConfig.RegisterRoutes(RouteTable.Routes);
        }


Its check whether that request is present in the RouteTable or not.
If present call the routing in RouteConfig.cs under App_Start folder.

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );


MVCHandler:  It initiate the real process,find the proper controller and calls it.

Controller: Once  Controller found it looks requested action method in it.

Action Execution: Then do execution of that Action method.(Action Result is super class for all action methods).

View Result: Once it get executed return the result, There are different ways(action result,json result,file result etc).

View Engine: Now we have result of our action method we need to display that on view,for that we need mediator to transfer.So we use view engines for that(ASPX or Razor).

View: This is our final destination for the end user to display result.

Monday 5 January 2015

Let me tell you what is ASP.NET entirely.....



First of all, let me clear that ASP.NET MVC is not replacing ASP.NET WebForms. Both these development models exist and can be used to develop ASP.NET applications. Although both has pros and cons.


ASP.NET Web Forms
ASP.NET MVC
ASP.NET Web Forms uses Page controller pattern approach for rendering layout. In this approach, every page has it's own controller i.e. code-behind file that processes the request.
ASP.NET MVC uses Front Controller approach. That approach means ,a common controller for all pages, processes the requests.
No separation of concerns. As we discussed that every page (.aspx) has it's own controller (code behind i.e. aspx.cs/.vb file), so both are tightly coupled.
Very clean separation of concerns. View and Controller are neatly separate.
Because of this coupled behavior, automated testing is really difficult.
Testability is key feature in ASP.NET MVC. Test driven development is quite simple using this approach.
In order to achieve stateful behavior, viewstate is used. Purpose was to give developers, the same experience of a typical WinForms application.
ASP.NET MVC approach is stateless as that of the web. So here no concept of viewstate.
Statefulness has a lots of problem for web environment in case of excessively large viewstate. Large viewstate means increase in page size.
As controller and view are not dependent and also no viewstate concept in ASP.NET MVC, so output is very clean.
ASP.NET WebForms model follows a Page Life cycle.
No Page Life cycle like WebForms. Request cycle is simple in ASP.NET MVC model.
Along with statefulness, microsoft tries to introduce server-side controls as in Windows applications. Purpose was to provide  somehow an abstraction to the details of HTML. In ASP.NET Web Forms, minimal knowledge of HTML, JavaScript and CSS is required.
In MVC, detailed knowledge of HTML, JavaScript and CSS is required.
Above abstraction was good but provides limited control over HTML, JavaScript and CSS which is necessary in many cases.
Full control over HTML, JavaScript and CSS.
With a lots of control libraries availability and limited knowledge of other related technologies, ASP.NET WebForms is RAD(Rapid Application Development) approach.
It's a step back. For developers decrease in productivity.
It’s good for small scale applications with limited team size.
It’s better as well as recommended approach for large-scale applications where different teams are working together.

Sunday 26 October 2014

MVC Architecture:It is not entirely different from ASP.Net if you spend 10-15 days you will become good developer in MVC as well, trust me.........