inside asp.net mvc framework

23
Inside ASP.NET MVC framework Alexander Beletsky, E- conomic http://beletsky.net @alexbeletsky

Upload: ciklum

Post on 26-May-2015

897 views

Category:

Technology


1 download

DESCRIPTION

This presentation was shared by The talk is dedicated for developers who is already experienced ASP.NET MVC framework, but always being interested - "What's inside?". We are going to have a journey talking about major workflows and aspects of framework operations: from IIS request into View rendering. That would be much helpful for better undertanding of framework, make your work more productive and fun

TRANSCRIPT

Page 1: Inside ASP.NET MVC framework

Inside ASP.NET MVC framework

Alexander Beletsky, E-conomichttp://beletsky.net

@alexbeletsky

Page 2: Inside ASP.NET MVC framework

ASP.NET MVC is cool!Why?

Page 3: Inside ASP.NET MVC framework

Hey, it's open source

• See what happens behind the curtain• Improve your knowledge• Learn from best• Super fun

Page 4: Inside ASP.NET MVC framework

ASP.NET or ASP.NET MVC  ?

Have you heard such question?

Page 5: Inside ASP.NET MVC framework

ASP.NET is foundation

• Request processing engine• Pushing request thought pipeline• Pipeline consists of Modules• And ends with Handler

Page 6: Inside ASP.NET MVC framework

MvcHanlder - heart of ASP.NET MVC

• Implements IHttpAsyncHandler, IHttpHandler• Creates the ControllerFactory• Execute the controller

Page 7: Inside ASP.NET MVC framework

Show me the code

Page 8: Inside ASP.NET MVC framework

Who is responsible for calling MvcHander?

Page 9: Inside ASP.NET MVC framework

Here comes Routing

• Included in framework 3.5 SP1• Implements recomendations by Jakob Nielsen• Save us of URL re-writing module• Provides decoupling of URL and page

Page 10: Inside ASP.NET MVC framework

Route = URL + Constraints + IRouteHanlder

Page 11: Inside ASP.NET MVC framework

Show me the code

Page 12: Inside ASP.NET MVC framework

ControllerBuilder & ControllerFactory

• ControllerBuilder creates ControllerFactory• ControllerFactory creates Controller

Page 13: Inside ASP.NET MVC framework

Difference in MVC2  and MVC3

• MVC2 ControllerBuilder creates factory "directly"• MVC3 ControllerBuilder uses SingleServiceResolver• SingleServiceResolver depends on IDependencyResolver

Page 14: Inside ASP.NET MVC framework

Show me the code

Page 15: Inside ASP.NET MVC framework

IDependencyResolver

• Bridge between ASP.NET MVC and IoC container• Very simple interface• Introduce extensibility for many entities

Page 16: Inside ASP.NET MVC framework

Show me the code

Page 17: Inside ASP.NET MVC framework

Controller Execution

• Get the name of the Action from Route• Call ControllerActionInvoker to Invoke action

Page 18: Inside ASP.NET MVC framework

Filters

• Authorization filters – Implements the IAuthorizationFilter attribute.

• Action filters – Implements the IActionFilter attribute.• Result filters – Implements the IResultFilter attribute.• Exception filters – Implements the IExceptionFilter attribute.

Page 19: Inside ASP.NET MVC framework

Why use filters?

• DRY code• AOP principles in action• Better reuse• Clean code• MVC3 introduces global filters

Page 20: Inside ASP.NET MVC framework

Show me the code

Page 21: Inside ASP.NET MVC framework

Action Results

• ViewResult - Represents HTML and markup.• EmptyResult - Represents no result.• RedirectResult - Represents a redirection to a new URL.• JsonResult - Represents a JavaScript Object Notation result

that can be used in an AJAX application.• JavaScriptResult - Represents a JavaScript script.• ContentResult - Represents a text result.• FileContentResult - Represents a downloadable file (with

the binary content).• FilePathResult - Represents a downloadable file (with a

path).• FileStreamResult - Represents a downloadable file (with a

file stream).

Page 22: Inside ASP.NET MVC framework

Action Result rendering

• Extract view name from Route• Find view associated with with Route & Action Result• Render the view

Page 23: Inside ASP.NET MVC framework

THANK YOU!

http://www.beletsky.net/search/label/InsideMVCtwitter: @alexbeletsky