Asp.Net MVC Adnan Masood Jeff Bergman Sean Xiao
Why MVC? Very Clean separation of Concerns Very Clean separation of Concerns Unit Testing Unit Testing Model that leads you down a maintainable path (prevent crappy code) Model that leads you down a maintainable path (prevent crappy code) Clean Urls and Html Clean Urls and Html
Front Controller Classic asp.net framework is Page Controller Classic asp.net framework is Page Controller Map Urls to classes/controllers instead of Pages Map Urls to classes/controllers instead of Pages
Unit Testing Mock Objects to simulate responses. Mock Objects to simulate responses. Don’t have to go through a page or view Don’t have to go through a page or view Red/Green Testing Red/Green Testing
Features Routing Routing Controller Controller View View Dependency Injection Dependency Injection Pluggable Pluggable Interfaces for all core contracts Interfaces for all core contracts
Urls Url no longer points to the view/aspx page Url no longer points to the view/aspx page A Url maps to a controller class A Url maps to a controller class Allows more flexibility to map Urls Allows more flexibility to map Urls Url routing engine, Route table Url routing engine, Route table Routes are tokenized strings Routes are tokenized strings Can use RegEx Can use RegEx
Route Examples / / / / Html.Link for creating outbound urls Html.Link for creating outbound urls Html.Link(,, ) Html.Link(,, )
Controller IController IController Execute(IHttpContext ctx, RouteData routeDate) Execute(IHttpContext ctx, RouteData routeDate) class MyController : Controller class MyController : Controller [ControllerAction] attribute [ControllerAction] attribute
Unit Testing Create instance of controller Create instance of controller controller.ViewEngine = new TestViewEngine(); controller.ViewEngine = new TestViewEngine(); Uses Mock Objects Uses Mock Objects
View Similar to existing page Similar to existing page No postback or view state No postback or view state Not all page events will fire Not all page events will fire Editing forms will be more work Editing forms will be more work Separate page for viewing, editing, and updating Separate page for viewing, editing, and updating Ajax will use UserControls as update panels but request still goes through the control Ajax will use UserControls as update panels but request still goes through the control
View View probably shouldn’t directly access data sources or services. View probably shouldn’t directly access data sources or services. Use the ViewData which stores the model the view is rendering Use the ViewData which stores the model the view is rendering ViewPage, ViewPage ViewPage, ViewPage
Future of Asp.Net MVC for the Enterprise MVC for the Enterprise Classic Asp.Net for quicker implementations Classic Asp.Net for quicker implementations
Thanks For Coming! PRIZES!!!! PRIZES!!!! Don’t forget we draw prizes on Sunday afternoon, including great products like Acronis and CodeSmith Tools, plus many new books! Don’t forget we draw prizes on Sunday afternoon, including great products like Acronis and CodeSmith Tools, plus many new books! THANKS AGAIN TO OUR CONTRIBUTORS!!!! THANKS AGAIN TO OUR CONTRIBUTORS!!!! Cal State Fullerton ( Cal State Fullerton ( Spherion ( Spherion ( Microsoft ( Microsoft ( Neudesic ( Neudesic ( PDSA Inc. ( PDSA Inc. ( QuickStart ( QuickStart ( Harbor Objects ( Harbor Objects ( Odyssey Consulting Group ( Odyssey Consulting Group ( IDesign Inc. ( IDesign Inc. (