www.dev-one.com ASP.NET MVC Fabian Vilers Twitter: @fvilers Hands on ABOUT DEV ONE Dev One is your dedicated par tner providing high quality exper ts on archite cture , development, and testing roles on IT projects using Microsof t .NET technologie s . Visit us on: http://www.dev -one.com We will help your enterprise to build a state of the ar t solution using the latest available technologies so you can rapidly deploy your applications and ser vices. Our proven experience, and a deep understanding of your business, will help us to you reduce your IT development costs and let your employees concentrate on your core business. We are aimed at providing consultancy exper ts on architecture, development, and testing roles, especially using the .NET technologies and the Microsof t ecosystem. With more than 10 years of multiple IT development experiences, we have forged a set of skills through various project & missions in several activity sectors that enables us to deliver you high quality ser vices. ASP.NET MVC – Hands on 2 AGENDA Presentation What is MVC? MVC on the web today ASP.NET MVC Timeline What web forms does well Where web forms doesn’t fit ASP.NET MVC believes Should you fear ASP.NET MVC? Comparison with ASP.NET web forms The MVC pattern Model View Controller What’s new in ASP.NET MVC 3 Demos Q & A ASP.NET MVC – Hands on 3 PRESENTATION ASP.NET MVC – Hands on 4 WHAT IS MVC? The MVC pattern is 30+ years old! It is a powerful and elegant means of separating concerns It makes it easier to test application It promotes parallel development thanks to the loose coupling between the three main components ASP.NET MVC – Hands on 5 MVC ON THE WEB TODAY Ruby on Rails Django and Python Spring, Struts and Java Zend Framework and PHP MonoRail … ASP.NET MVC – Hands on 6 ASP.NET MVC Separation of application tasks (input logic, business logic, and UI logic), testability, and test -driven development (TDD) by default An extensible and pluggable framework A powerful URL-mapping component that lets you build applications that have comprehensible and searchable URLs Convention over configuration Don’t repeat yourself, keep it simple (DRY/KISS principles) ASP.NET MVC – Hands on 7 TIMELINE • ScottGu sketched out the core of ASP.NET MVC (~100 lines of code) February 2007 September 2007 • Presenstation of Scalene at the Austin ALT.NET conference • First Community Technology Preview March 2009 • ASP.NET MVC 1.0 • ASP.NET MVC source code was released under the MS-PL December 2007 April 2009 ASP.NET MVC – Hands on March 2010 • ASP.NET MVC 2.0 • Shipped with Visual Studio 2010 • ASP.NET MVC 3.0 • Shipped with Visual Studio 2010 January 2011 8 COMPARISON WITH ASP.NET WEB FORMS ASP.NET MVC – Hands on 9 WHAT WEB FORMS DOES WELL Represent a Page as control tree Give these ser ver-side controls events like their desktop counterparts Hide as much HTTP and HTML as is reasonable Make state management as transparent as possible ASP.NET MVC – Hands on 10 WHERE WEB FORMS DOESN’ T FIT ViewState is powerful, but it has its drawbacks (weight,…) Page life cycle can be a nightmare Limited control over HTML Client IDs and the c t l 0 0 $ C o n t e n t P l a c e H o l d e r 1 $ U s e r C o n t r o l 1 $ T e x t B o x 1 syndrome It’s nearly impossible to run a Web Form through its life cycle outside IIS ASP.NET MVC – Hands on 11 ASP.NET MVC BELIEVES Guiding tenets: Be extensible, maintainable, and flexible Be testable Get out of the user ’s way when necessary Ser ving methods, not files Separation of concerns ScottHa said: « ASP.NET MVC is Web Forms unplugged » ASP.NET MVC – Hands on 12 SHOULD YOU FEAR ASP.NET MVC? ASP.NET MVC is built on top of ASP.NET ASP.NET MVC is not a replacement for anything It is just an alternative It’s a totally different approach ASP.NET MVC – Hands on 13 THE MVC PATTERN ASP.NET MVC – Hands on 14 THE MVC PATTERN Model objects are the parts of the application that implement the logic for the application’s data domain View components that display the application’s user interface Controller components that handle user interaction, work with the model, and ultimately select a view to render ASP.NET MVC – Hands on 15 MODEL Business logic and validation of the application’s data domain Totally independant from the views or the controllers Model state can be stored in memor y, database, XML files,… ASP.NET MVC – Hands on 16 VIEW Application’s user interface using data from the model No interaction with the models or the controllers Views can be strongly typed Almost no code ASP.NET MVC – Hands on 17 CONTROLLER Handle user interaction Quer y the model Select the right view to render ASP.NET MVC – Hands on 18 WHAT’S NEW IN ASP.NET MVC 3 ASP.NET MVC – Hands on 19 WHAT’S NEW IN ASP.NET MVC 3 Razor View Engine Suppor t for multiple view engine Global action filters « ViewBag » proper ty New « ActionResult » types JavaScript and A JAX improvements Client-side validation enabled by default Remote validator JSON binding suppor t Data annotations metadata attributes Validation interfaces Dependency injection improvements Par tial-Page Output Caching Granular Control over Request Validation … ASP.NET MVC – Hands on 20 DEMOS ASP.NET MVC – Hands on 21 BOOK STORE Using the ASP.NET MVC 3 template and playing around with Razor First data access and display a list of authors Manage authors Display a list of books Create and edit a book using the ViewModel pattern Source code available on: http://vil.rs/qK3rMG ASP.NET MVC – Hands on 22 Q&A ASP.NET MVC – Hands on 23 ASP.NET MVC – Hands on 24