ASP.NET MVC

18
ASP.NET MVC Under the Hood Paul Stovell Readify

Transcript of ASP.NET MVC

Page 1: ASP.NET MVC

ASP.NET MVC Under the Hood

Paul StovellReadify

Page 2: ASP.NET MVC

Agenda

ASP.NET MVC 101

ASP.NET MVC Pipeline Controller Factories Action Invokers Model Binders Action Filters Action Results View Engines

Page 3: ASP.NET MVC

Introducing ASP.NET MVC

Page 4: ASP.NET MVC

View

Model

Controller

GET /

Page 5: ASP.NET MVC

ASP.NET MVC Pipeline

Page 6: ASP.NET MVC

ASP.NET Request Pipeline

Internet

Module Module Module

Handler

Handler

Handler

Handler

Handler

public interface IHttpHandler{ void ProcessRequest( HttpContext context);

bool IsReusable { get; }}

Page 7: ASP.NET MVC

Web Forms<%@ Page Language="C#" CodeBehind="Default.aspx.cs" Inherits="Sample.DefaultPage" %>

<div> <asp:TextBox runat="server" /></div>

namespace ASP { public class default_aspx : Sample.DefaultPage, System.Web.IHttpHandler {

PreInitInit

InitCompletePreLoad

LoadControl EventsLoadComplete

PreRenderSaveStateComplete

RenderUnload

Page 8: ASP.NET MVC

MVC PipelineIntern

et

Module

MvcHandler

Module

RoutingController Factory

Controller.Execute()

Action Invoker

View Engine

Page 9: ASP.NET MVC

MVC Pipeline: Controller Factories

public interface IControllerFactory { IController CreateController( RequestContext requestContext, string controllerName);

void ReleaseController( IController controller); }

Page 10: ASP.NET MVC

MVC Pipeline: Controllers

public interface IController{ void Execute( RequestContext requestContext);}

Controller IActionInvoker

Page 11: ASP.NET MVC

MVC Pipeline: Action Invoker

public interface IActionInvoker{ bool InvokeAction( ControllerContext controllerContext, string actionName);}

Page 12: ASP.NET MVC

Action Invoker

MVC Pipeline: Action Invoker

Find Action

Authorization Filters

Request Validation

Model Binders

Invoke

Execute Action Result

Pre-Action Filters

Post-Action Filters

Page 13: ASP.NET MVC

MVC Pipeline: Model Binders

public interface IModelBinder{ object BindModel( ControllerContext controllerContext, ModelBindingContext bindingContext);}

Page 14: ASP.NET MVC

MVC Pipeline: Action Filters

public interface IActionFilter{ void OnActionExecuting( ActionExecutingContext filterContext);

void OnActionExecuted( ActionExecutedContext filterContext);}

Page 15: ASP.NET MVC

MVC Pipeline: Action Results

public abstract class ActionResult{ public abstract void ExecuteResult( ControllerContext context);}

ViewResultBase

ViewResultPartialViewRes

ult

RedirectResult

JsonResult FileResult

Page 16: ASP.NET MVC

MVC Pipeline: View Engines

public interface IViewEngine{ ViewEngineResult FindPartialView( ControllerContext controllerContext, string partialViewName, bool useCache);

ViewEngineResult FindView( ControllerContext controllerContext, string viewName, string masterName, bool useCache);

void ReleaseView( ControllerContext controllerContext, IView view);}

Page 17: ASP.NET MVC

Summary