140 likes | 315 Views
Asp.Net MVC. Adnan Masood Jeff Bergman Sean Xiao. Why MVC?. Very Clean separation of Concerns Unit Testing Model that leads you down a maintainable path (prevent crappy code) Clean Urls and Html. Front Controller. Classic asp.net framework is Page Controller
E N D
Asp.Net MVC Adnan Masood Jeff Bergman Sean Xiao
Why MVC? • Very Clean separation of Concerns • Unit Testing • Model that leads you down a maintainable path (prevent crappy code) • Clean Urls and Html
Front Controller • Classic asp.net framework is Page Controller • Map Urls to classes/controllers instead of Pages
Unit Testing • Mock Objects to simulate responses. • Don’t have to go through a page or view • Red/Green Testing
Features • Routing • Controller • View • Dependency Injection • Pluggable • Interfaces for all core contracts
Urls • Url no longer points to the view/aspx page • A Url maps to a controller class • Allows more flexibility to map Urls • Url routing engine, Route table • Routes are tokenized strings • Can use RegEx
Route Examples • <Controller>/<Action>/<Param> • http://domain/Home/CustomerDetail/45 • Html.Link for creating outbound urls • Html.Link(<Friendly Name>, <Action>, <Controller>)
Controller • IController • Execute(IHttpContext ctx, RouteData routeDate) • class MyController : Controller • [ControllerAction] attribute
Unit Testing • Create instance of controller • controller.ViewEngine = new TestViewEngine(); • Uses Mock Objects
View • Similar to existing page • No postback or view state • Not all page events will fire • Editing forms will be more work • Separate page for viewing, editing, and updating • 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. • Use the ViewData which stores the model the view is rendering • ViewPage<T>, ViewPage
Future of Asp.Net • MVC for the Enterprise • Classic Asp.Net for quicker implementations
Thanks For Coming! • PRIZES!!!! • 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!!!! • Cal State Fullerton (http://www.fullerton.edu) • Spherion (www.spherion.com) • Microsoft (www.microsoft.com) • Neudesic (www.neudesic.com) • PDSA Inc. (www.pdsa.com) • QuickStart (www.quickstart.com) • Harbor Objects (www.harborobjects.com) • Odyssey Consulting Group (www.ocgpros.com) • IDesign Inc. (www.idesign.net)