Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

ASP.NET MVC is cool! Why?

Slide 3

Slide 3 text

Hey, it's open source ● See what happens behind the curtain ● Improve your knowledge ● Learn from best ● Super fun

Slide 4

Slide 4 text

ASP.NET or ASP.NET MVC ? Have you heard such question?

Slide 5

Slide 5 text

ASP.NET is foundation ● Request processing engine ● Pushing request thought pipeline ● Pipeline consists of Modules ● And ends with Handler

Slide 6

Slide 6 text

MvcHanlder - heart of ASP.NET MVC ● Implements IHttpAsyncHandler, IHttpHandler ● Creates the ControllerFactory ● Execute the controller

Slide 7

Slide 7 text

Show me the code

Slide 8

Slide 8 text

Who is responsible for calling MvcHander?

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Route = URL + Constraints + IRouteHanlder

Slide 11

Slide 11 text

Show me the code

Slide 12

Slide 12 text

ControllerBuilder & ControllerFactory ● ControllerBuilder creates ControllerFactory ● ControllerFactory creates Controller

Slide 13

Slide 13 text

Difference in MVC2 and MVC3 ● MVC2 ControllerBuilder creates factory "directly" ● MVC3 ControllerBuilder uses SingleServiceResolver ● SingleServiceResolver depends on IDependencyResolver

Slide 14

Slide 14 text

Show me the code

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Show me the code

Slide 17

Slide 17 text

Controller Execution ● Get the name of the Action from Route ● Call ControllerActionInvoker to Invoke action

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

Why use filters? ● DRY code ● AOP principles in action ● Better reuse ● Clean code ● MVC3 introduces global filters

Slide 20

Slide 20 text

Show me the code

Slide 21

Slide 21 text

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).

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

THANK YOU! http://www.beletsky.net/search/label/InsideMVC twitter: @alexbeletsky