ASP.NET MVC in Action Austin Code Camp, 2009 Jeffrey Palermo Chief Technology Officer Headspring Systems.

Slides:



Advertisements
Similar presentations
Introduction to ASP.NET MVC
Advertisements

INTRODUCTION TO ASP.NET MVC AND EXAMPLE WALKTHROUGH RAJAT ARYA EFECS - OIM DAWG – 4/21/2009 ASP.NET MVC.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Web Applications Development Using Coldbox Platform Eddie Johnston.
Fabian Vilers Hands on ASP.NET MVC.
Anatomy of an ASP.NET Page. Slide 2 My Version of the Big Picture (1) ASP Worker (Engine) Your application Runs Server Other applications User 1User 2.
Razor. Slide 2 Remember this? Browser Web Server HTTP Request HTTP Response (Web page / code) Client code (script) Interpret request Generate HTML and.
ASP MVC s/mvc-4/getting-started-with- aspnet-mvc4/intro-to-aspnet- mvc-4.
Virtual techdays INDIA │ November 2010 ASP.Net MVC Deep Dive Sundararajan S │ Associate Tech Architect, Aditi Technologies.
AMS304: Introduction to the ASP.NET Model View Controller (MVC) Framework Scott Hanselman Eilon Lipton Microsoft Microsoft
UNIT-V The MVC architecture and Struts Framework.
ASP.NET 4.0 Web Developers User Group Israel June 2009.
Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Ori Calvo, 2010 “If people want to have maximum reach across *all* devices then HTML will provide the broadest reach” Scott Guthrie,
Jess Chadwick Lead Code Monkey Infragistics Website Team Todd Snyder Development Team Lead Infragistics Experience Design Group.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
Building Web Sites with ASP.NET MVC Framework Noam King CTO Sela College
DEV402 Extending the ASP.NET Runtime Jurgen Postelmans Microsoft Regional Director BeLux U2U.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Architecture.
Are you getting the benefits from ASP.NET and AJAX? Introduction to the CTC ASP.NET Webforms Generator.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Beginning ASP.NET (Part 3).NET 2.0 Core Libraries Tuc Goodwin.
Getting Started with ASP.NET MVC BRIJ BHUSHAN MISHRA.
Getting started with ASP.NET MVC Dhananjay
ASP.Net MVC Extensibility, scalability and testability Andrew Locatelli Woodcock.
Leverage NHibernate in your architecture without tight coupling Presented by Jeffrey Palermo CTO, Headspring Systems Microsoft MVP, MCSD.Net
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
ASP.NET MVC Telerik Academy
 An essential supporting structure of any thing  A Software Framework  Has layered structure ▪ What kind of functions and how they interrelate  Has.
TDD, DI, and SoC with ASP.NET MVC Presented by Jeffrey Palermo CTO, Headspring Systems Microsoft MVP, MCSD.Net
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
Virtual techdays INDIA │ 9 th – 11 th January 2011 ASP.Net MVC Sundararajan S │ Associate Tech Architect, Aditi Technologies.
Scott Guthrie
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Virtual techdays INDIA │ 9-11 February 2011 SESSION TITLE Kamala Rajan S │ Technical Manager, Marlabs.
Headspring Certified Training.Net Boot Camp: From Journeyman to Master Series Presented by Jeffrey Palermo CTO, Headspring Systems Microsoft MVP, MCSD.Net.
2 Architectural Considerations for the ASP.NET MVC Framework Jeffrey Palermo Chief Technology Officer Headspring Systems Austin, TX Session Code: ARC402.
2 Architectural Concerns for Object/Relational Mappers (O/R-M) with Examples in NHibernate Jeffrey Palermo Chief Technology Officer Headspring Systems,
Jean-Claude Trachsel Senior Consultant, Trivadis AG The good news.
Introduction to ASP.NET development. Background ASP released in 1996 ASP supported for a minimum 10 years from Windows 8 release ASP.Net 1.0 released.
Intro to MVC5 Bryan Soltis Bit-Wizards - Director of Technology & Research.
The New Face of ASP.NET ASP.NET MVC, Razor, and jQuery Ido Flatow | Senior Architect | Sela | This session is.
ASP.NET Architecture Mike Taulty Developer & Platform Group Microsoft Ltd
//liveVirtualacademy2011/ What’s New for ASP.NET 4.5 and Web Development in Visual Studio 11 Developer Preview Γιώργος Καπνιάς MVP, MCT, MCDP, MCDBA, MCTS,
INTRODUCTION TO MVC BY SUHA MNEIMNEH. WHAT’S THE AGENDA What is MVC? MVC components MVC vs web forms vs ASP.NET vocabulary When to create MVC application.
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel
Introduction to ASP.NET MVC [Name] [ Address] [Blog URL]
Introduction to MVC Slavomír Moroz. Revision from Previous Lesson o ASP.NET WebForms applications Abstract away HTTP (similar to desktop app development)
Build Data Driven Apps with ASP.NET Core Rachel Appel.
Jim Fawcett CSE686 – Internet Programming Spring 2014
Getting Started with MVC 5 and Visual Studio 2013
An introduction to ASP.Net with MVC Nischal S
Jim Fawcett CSE686 – Internet Programming Spring 2012
Social Media And Global Computing Introduction to The MVC Pattern
Node.js Express Web Applications
MVC Architecture, Symfony Framework for PHP Web Apps
ASP MVP Web applications and Razor
Play Framework: Introduction
Haritha Dasari Josue Balandrano Coronel -
ASP.NEXT The ASP.NET 3.5 Extensions
Anatomy of an ASP.NET Page
Controllers.
ASP.NET MVC Imran Rashid CTO at ManiWeber Technologies.
Chengyu Sun California State University, Los Angeles
Presentation transcript:

ASP.NET MVC in Action Austin Code Camp, 2009 Jeffrey Palermo Chief Technology Officer Headspring Systems

ASP.NET MVC History Getting Started The Model Controllers/Actions Views Routes AJAX MvcContrib Questions

3 ASP.NET MVC History Oct 2007 – Scott Guthrie provides first glimpse at Alt.Net Conf in Austin, TX Dec 2007 – First official CTP released Dec 2007 – MvcContrib open source project launches 2008 – 4 more CTPs released Mar 2009 – First version released Mar 2009 – MvcContrib 1.0 released Today – Lots of buzz

4 Getting Started - Pattern

5 Getting Started - Components.Net 3.5 SP1 System.Web.Abstractions.dll HttpContextBase HttpRequestBase etc System.Web.Routing.dll ASP.NET MVC v1.0 System.Web.Mvc.dll Extras MvcContrib.dll Microsoft.Web.Mvc.dll

6 Getting Started - Responsibilities Controllers Responsible for WHAT a screen does. Views Responsible for DISPLAYING the screen. Models Responsible for REPRESENTING the task.

7 Getting Started - Advantages Decouples rendering logic from handling user input Decouples screen logic from processing the http request Leverages interfaces to separate responsibilities within the presentation layer Provides complete control over markup rendered Provides complete control over urls Different presentation concerns can be independently tested

8 Getting Started - Web Forms? ASP.NET HttpApplication HttpContext HttpRequest HttpResponse HttpRuntime HttpUtility IHttpHandler IHttpModule WebForms Server Lifecycle Postback ViewState ASPX MasterPages Themes, Skins General Templating

9 Getting Started - ASP.NET MVC? ASP.NET HttpApplication HttpContext HttpRequest HttpResponse HttpRuntime HttpUtility IHttpHandler IHttpModule Mvc Routes Controllers ViewData Filters MvcContrib ASPX MasterPages Themes, Skins General Templating

10 Getting Started – New Project

11 Getting Started – Project Structure

12 Getting Started - Routes Old g=april09 ASP.NET MVC { key1}/{ key2 } Default: {controller}/{action}/{id} ProductController.cs public ViewResult Edit(string id){…}

13 Flow of an ASP.NET MVC Request Request comes in to /Home IIS determines the request should be handled by ASP.NET ASP.NET gives all HttpModules a chance to modify the request The UrlRoutingModule determines that the URL matches a route configured in the application

14 Flow of an ASP.NET MVC Request The UrlRoutingModule gets the appropriate IHttpHandler from the IRouteHandler that is used in the matching route (most of the time, MvcRouteHandler)as the handler for the request The MvcRouteHandler constructs and returns MvcHandler. The MvcHandler, which implements IHttpHandler executes ProcessRequest.

15 Flow of an ASP.NET MVC Request The MvcHandler uses IControllerFactory to obtain an instance of IController using the "controller" route data from the route {controller}/{action}/{id}. The HomeController is found, and its Execute method is invoked. The HomeController invokes the Index action.

16 Flow of an ASP.NET MVC Request The Index action adds some objects to the ViewData dictionary. The HomeController invokes the ActionResult returned from the action, which renders a view. The “index” view in the views folder displays the objects in ViewData. The view, derived from System.Web.Mvc.ViewPage, executes its ProcessRequest method. ASP.NET renders the response to the browser.

18 Model - Long-lived architecture What causes legacy code? Dependencies Coupling Lack of validated feedback (testing)

19 Model - Layered Architecture Data Access/Infrastructure Business Logic UI

20 Model - Layered Architecture Business Logic UI Data Access I/O WCF

21 Web Service File Model - Solution Structure Client Business Logic Data Access DB Infrastructure

22 Model - Onion Architecture Objects (aggregates) Domain Services User Interface Infrastructure Tests DB Web Service File Application Core/Domain Model SpeakerControllerSpeakerController IUserSessionIUserSession IConferenceRepositoryIConferenceRepository UserSession<<class>>UserSession<<class>> ConferenceRepository<<class>>ConferenceRepository<<class>>

23 Web Service File Model - Solution Structure UI Core Infrastructure DB IoC Container

24 Model - Onion Architecture (flattened) Domain Services UI Data Access I/O WCF Aggregates (entities)

25 Model - Data-Driven Architecture Infrastructure Business Logic More Business Logic User Interface Tests DB Web Service File Application Core

27 Controllers – Icontroller

28 Controllers – Action

29 Controllers – Action Requirements The method must be public. The method cannot be a static method. The method cannot be an extension method. The method cannot be a constructor, getter, or setter. The method cannot have open generic types. The method is not a method of the controller base class. The method cannot contain ref or out parameters.

30 Controllers – Action return types

31 Controllers – ActionResult

32 Controllers – Parameter Binding

33 Controllers – Parameter Binding public ActionResult Save(string conferenceKey, string firstName, string lastName, string , string webpage) { //method body omitted. }

34 Controllers – Parameter Binding Precedence 1.Form values 2.Route arguments 3.Querystring parameters

35 Controllers – Parameter Binding public class AttendeeForm { public virtual Guid ConferenceID { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public virtual string Address { get; set; } public virtual string Webpage { get; set; } } //resulting action method signature public ActionResult Save(AttendeeForm form){}

36 Controllers – Model Binding

37 Controllers – Model Binding /conference/edit?conference=austincodecamp public ActionResult Edit(Conference conference){…}

38 Controllers – Registering Binders

39 Controllers – ViewData

40 Controllers – Filters

41 Controllers – Action Filters IActionFilter – before and after hooks when an action is executing IResultFilter – before and after hooks when an action result is executing IAuthorizationFilter – hooks when the controller is authorizing the current user IExceptionFilter - hooks when an exception occurs during the execution of a controller

42 Controllers – Provided ActionFilters System.Web.Mvc.ActionFilterAttribute System.Web.Mvc.OutputCacheAttribute System.Web.Mvc.HandleErrorAttribute System.Web.Mvc.AuthorizeAttribute System.Web.Mvc.ValidateAntiForgeryTokenAttribute System.Web.Mvc.ValidateInputAttribute

43 Controllers – Applying Filters

44 Controllers – Action Selectors System.Web.Mvc.AcceptVerbsAttribute – limits action selection to requests of the specified verb type System.Web.Mvc.NonActionAttribute – prevents action method from being selected

46 Views – Folder Structure

47 Views – IViewEngine

48 Views – View not found

49 Views – IView

50 Views – WebFormViewEngine Uses code nuggets No code-behind Leverages Master Pages Partial views can be.aspx or.ascx Responsibility is rendering markup

51 Views – Helpers System.Web.Mvc.HtmlHelper - Used to help render html input elements Html.TextBox() Html.CheckBox() System.Web.Mvc.UrlHelper – Used to render URLS Url.Action() Url.Content() Url.RouteUrl() System.Web.Mvc.AjaxHelper - Used to render links and form elements used in an ajax request Ajax.ActionLink() Ajax.BeginForm()

52 Views – Strongly Typed

53 Views – Strongly Typed

54 Views – Html Helper Binding Values will be bound if: 1.The name is found in ModelState 2.The name is found as an explicit key in view data. 3.The name is found as a property of ViewData.Model. 4.The name is an expression interpretable, such as Product.Name or Products[2].Name.

55 Views – Validation

56 Views – ModelState Validation

57 Views – Controls

58 Views – Custom View Helper

60 Routes – Overview

61 Routes – Designing Urls Make simple, clean URLs. Make hackable URLs. It is OK for URL parameters to clash. Keep URLs short. Avoid exposing database IDs wherever possible. Consider adding unnecessary information.

62 Routes – Hackable Urls

63 Routes – RESTful URLVERBACTION /sessionsGETList all sessions /sessionsPOSTAdd a new session /sessions/5GETShow session with id 5 /sessions/5PUTUpdate session with id 5 /sessions/5DELETEDELETE session with id 5 /sessions/5/comments GETList comments for session with id 5

64 Routes – Default

65 Routes – Route Values

66 Routes – Constraints

67 Routes – Testing "~/austinCodeCamp/attendees/new".ShouldMapTo ( x => x.New("austinCodeCamp")); "~/austinCodeCamp/attendees/123/bob-johnson".ShouldMapTo ( x => x.Show("austinCodeCamp", 123)); "~/login".ShouldMapTo (x => x.Login()); "~/conference/new".ShouldMapTo (x => x.New());

68 Routes – Infinite Flexibility

70 MvcContrib Founded by Eric Hexter and Jeffrey Palermo Multiple view engines ViewDataExtensions IoC Container support Html helpers Extra ActionFilters Anything else the community contributes

72 About me CTO, Headspring Systems Agile coach MCSD.Net Microsft MVP, ASPInsider Certified ScrumMaster Director, Austin.Net User Group INETA speakers bureau U.S. Army Veteran Party with Palermo Headspring’s Agile Boot Camp