• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction To ASP.NET MVC
 

Introduction To ASP.NET MVC

on

  • 9,168 views

This is a presentation I gave to the Charteris TechDay in January 2008 and will be giving at DDD Ireland.

This is a presentation I gave to the Charteris TechDay in January 2008 and will be giving at DDD Ireland.

Statistics

Views

Total Views
9,168
Views on SlideShare
9,026
Embed Views
142

Actions

Likes
1
Downloads
327
Comments
0

24 Embeds 142

http://knitinr.blogspot.com 91
http://knitinr.blogspot.ca 8
http://knitinr.blogspot.com.br 5
http://www.slideshare.net 4
http://knitinr.blogspot.it 3
http://knitinr.blogspot.in 3
http://knitinr.blogspot.de 3
http://knitinr.blogspot.com.au 3
http://knitinr.blogspot.sg 2
http://knitinr.blogspot.fi 2
http://knitinr.blogspot.com.es 2
http://www.linkedin.com 2
http://dotnetgold.com 2
http://knitinr.blogspot.ae 2
http://knitinr.blogspot.se 1
http://knitinr.blogspot.cz 1
http://knitinr.blogspot.co.nz 1
http://knitinr.blogspot.co.at 1
http://knitinr.blogspot.fr 1
http://knitinr.blogspot.co.uk 1
http://translate.googleusercontent.com 1
http://www.dotnetgold.com 1
http://localhost:50428 1
http://knitinr.blogspot.jp 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction To ASP.NET MVC Introduction To ASP.NET MVC Presentation Transcript

  • Introducing ASP.NET MVC Alan Dean, Senior Technologist
    • Model-View-Controller (MVC)
    • is a well-known design pattern
    • The original 1978 implementation is described
    • in depth in the influential 1992 paper
      • “ Applications Programming in Smalltalk-80:
      • How to use Model-View-Controller (MVC)”
      • by Steve Burbeck
    • …“ the concept of the design pattern in software provides a key to helping developers leverage the expertise of other skilled architects.”
      • Grady Booch, 1995
  •  
  • MVC consists of three kinds of objects
    • The Model is the application object
    • The View is the screen presentation
    • The Controller defines the way the user interface reacts to user input
    • Before MVC, user interface designs tended
    • to lump these objects together
    • MVC decouples them to
    • increase flexibility and reuse
  • Controller Model View
      • In his paper
      • Steve Burbeck describes two variations of MVC
    • a passive model and an active model
    • The passive model is employed when one controller manipulates the model exclusively
    • The controller modifies the model and then informs the view that the model has changed and should be refreshed
    • The model in this scenario is completely independent of the view and the controller, which means that there is no means for the model to report changes in its state
  • Controller View Model handleEvent service update getData
    • The HTTP protocol is an example of this.
    • The browser displays the view and responds to user input, but it does not detect changes in the data on the server.
    • Only when the browser explicitly requests a refresh is the server interrogated for changes.
  • Separation of Concerns (SoC)
    • Object types become ‘pluggable’
    • Intra-team dependency is reduced
    • Testability is enhanced
    • Application flow can be hard to grok
  • MVC Web Frameworks
    • Java has Swing , Struts , Grails and others
    • Perl has Catalyst , Gantry , Jifty and others
    • PHP has Zend , Zoop , Agavi and others
    • Python has Django , Gluon , Pylon and others
    • Ruby on Rails is famously ‘opinionated’
    • … and .NET?
  • .NET MVC Web Frameworks
    • Spring.NET
      • http://www.springframework.net/
    • Maverick.NET
      • http://mavnet.sourceforge.net/
    • MonoRail
      • http://www.castleproject.org/monorail/
    • … and now ASP.NET MVC from Microsoft
      • http://asp.net/downloads/3.5-extensions/
    • “ The ASP.NET MVC framework is a lightweight, highly testable presentation framework that is integrated with existing ASP.NET features, such as master pages and membership-based authentication.
    • The MVC framework is defined in the System.Web.Mvc namespace and is a fundamental, supported part of the System.Web namespace”
  • Demo Create a new ASP.NET MVC Solution
  • HTTP Request Flow HTTP Response GET /Home/Index HTTP/1.1 HTTP Request Route Handler Controller Model View
  • HTTP Request Flow public class Global : HttpApplication { protected void Application_Start( object sender, EventArgs e) { RouteTable .Routes.Add( new Route { Url = "[controller]/[action]/[id]" , Defaults = new { action = "Index" , id = ( string ) null }, RouteHandler = typeof ( MvcRouteHandler ) }); } } HTTP Response Route Handler HTTP Request Controller Model View
  • HTTP Request Flow public class HomeController : Controller { [ ControllerAction ] public void Index() { CompanyInfo companyInfo = new CompanyInfo (); companyInfo.CompanyName = "Your company name here" ; RenderView( "Index" , companyInfo); } } HTTP Response Controller HTTP Request Route Handler Model View
  • HTTP Request Flow public class CompanyInfo { public string CompanyName { get ; set ; } } HTTP Response Model HTTP Request Route Handler Controller View
  • HTTP Request Flow public partial class Index : ViewPage < CompanyInfo > { } Response View <% @ Page Language =&quot;C#&quot; AutoEventWireup =&quot;true&quot; CodeBehind =&quot;Index.aspx.cs&quot; Inherits =&quot;MvcApplication.Views.Home.Index&quot; %> < html > < head > < title > <%= this.ViewData.companyName %> </ title > </ head > < body > <%= Html.ActionLink( “Homepage&quot; , &quot;Index&quot; , &quot;Home&quot; ) %> < div > Welcome! </ div > </ body > </ html > HTTP Request Route Handler Controller Model
  • HTTP Request Flow HTTP/1.1 200 OK Content-Type: text/html <html> <head> <title>Your company name here</title> </head> <body> <a href=&quot;/Home/Index&quot;>Index</a> <div>Welcome!</div> </body> </html> HTTP Request Route Handler Controller Model View HTTP Response
  • Wiki A wiki is software that allows users to create, edit, and link web pages easily
    • Ward Cunningham, developer of the first wiki, WikiWikiWeb , originally described it as
    • &quot;the simplest online database that could possibly work&quot;
  • Wiki Database
    • CREATE TABLE [dbo].[PageTable]
    • (
    • [Id] int IDENTITY (1,1) NOT NULL ,
    • [Guid] uniqueidentifier NOT NULL ,
    • [LastModified] datetime NOT NULL ,
    • [Removed] datetime NULL ,
    • [Title] varchar (255) NOT NULL ,
    • [Body] ntext NOT NULL
    • );
  • Wiki HTTP API
    • GET /
      • GET /page.html
    • POST /page
    • GET /page/[title]
      • GET /page/[title].txt
      • GET /page/[title].html
      • GET /page/[title].atom
    • PUT /page/[title]
    • DELETE /page/[title]
  • GET
    • The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.
    • Safe & Idempotent
    • GET /
    • Accept: text/html, */*
    • 303 See Other
    • Location: http://localhost/page.html
    • Cache-Control: public
    • Expires: Thu, 31 Jan 2008 16:00:00 GMT
    • GET /page.html
    • Accept: text/html, */*
    • 200 OK
    • Content-Type: text/html
    • Cache-Control: public
    • Expires: Thu, 31 Jan 2008 16:00:00 GMT
    • <html>
    • <head><title>…</title></head>
    • <body>
    • <form
    • action=&quot; /page &quot; method=&quot; post &quot;
    • enctype=&quot; application/x-www-form-urlencoded &quot;>
    • <input type=&quot;text&quot; name=&quot;title&quot; maxlength=&quot;255&quot; />
    • <textarea name=&quot;body&quot; rows=&quot;25&quot; cols=&quot;80&quot;></textarea>
    • <input type=&quot;submit&quot; value=&quot;Create Page&quot; />
    • </form>
    • </body>
    • </html>
  • POST
    • The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI
    • POST /page
    • Content-Type: application/x-www-form-urlencoded
    • title=Welcome&body=Welcome+to+my+new+wiki.
    • 201 Created
    • Content-Type: text/html
    • Content-Location: http://localhost/page/Welcome
    • Cache-Control: no-cache
    • <html>
    • <head>
    • <title>…</title>
    • <meta http-equiv=&quot; refresh &quot;
    • content=&quot;0;url= http://localhost:64701/page/Welcome &quot;>
    • </head>
    • <body>…</body>
    • </html>
    • GET /page/Welcome
    • Accept: text/html, */*
    • 303 See Other
    • Location: http://localhost/page/Welcome.html
    • Cache-Control: public
    • Last-Modified: Tue, 29 Jan 2008 16:00:00 GMT
    • Vary: Accept
    • GET /page/Welcome.html
    • Accept: text/html, */*
    • 200 OK
    • Content-Type: text/html
    • Content-Location: http://localhost/page/Welcome
    • Cache-Control: public
    • Last-Modified: Tue, 29 Jan 2008 16:00:00 GMT
    • <html>
    • <head>
    • <title>…</title>
    • <link
    • href=&quot; http://localhost/page/Welcome.atom &quot;
    • rel=&quot; alternate &quot; title=&quot;…&quot;
    • type=&quot; application/atom+xml &quot; />
    • </head>
    • <body>…</body>
    • </html>
    • GET /page/Welcome.atom
    • Accept: application/atom+xml
    • 200 OK
    • Content-Type: application/atom+xml
    • Content-Location: http://localhost/page/Welcome
    • Cache-Control: public
    • Last-Modified: Tue, 29 Jan 2008 16:00:00 GMT
    • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8”?>
    • <feed xml:lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/2005/Atom&quot;>
    • <link href=&quot; http://localhost:64701/page/Welcome &quot; rel=&quot; source &quot; />
    • <link href=&quot; http://localhost:64701/page/Welcome.atom &quot; rel=&quot; self &quot; type=&quot;application/atom+xml&quot; hreflang=&quot;en&quot; title=&quot;…&quot; />
    • <link href=&quot; http://localhost:64701/page/Welcome.html &quot; rel=&quot; alternate &quot; type=&quot;text/html&quot; hreflang=&quot;en&quot; title=&quot;…&quot; />
    • <link href=&quot; http://localhost:64701/page/Welcome.txt &quot; rel=&quot; alternate &quot; type=&quot;text/plain&quot; hreflang=&quot;en&quot; title=&quot;…&quot; />
    • <entry>…</entry>
    • </feed>
    • GET /page/Welcome
    • Accept: text/plain
    • 303 See Other
    • Location: http://localhost/page/Welcome.txt
    • Cache-Control: public
    • Last-Modified: Tue, 29 Jan 2008 16:00:00 GMT
    • Vary: Accept
    • GET /page/Welcome.txt
    • Accept: text/plain
    • 200 OK
    • Content-Type: text/plain
    • Content-Location: http://localhost/page/Welcome
    • Cache-Control: public
    • Last-Modified: Tue, 29 Jan 2008 16:00:00 GMT
    • Welcome to my new wiki.
  • PUT
    • The PUT method requests that the enclosed entity be stored under the supplied Request-URI.
    • If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server.
    • Idempotent
    • PUT /page/Welcome
    • Content-Type: text/plain
    • Welcome to my new [[wiki]].
    • 204 No Content
    • Cache-Control: no-cache
  • DELETE
    • The DELETE method requests that the origin server delete the resource identified by the Request-URI.
    • Idempotent
    • DELETE /page/Welcome
    • 204 No Content
    • Cache-Control: no-cache
  •  
    • RE presentational S tate T ransfer
  • REST: The Web Used Correctly
    • A system or application architecture
    • … that uses HTTP, URI and other Web
    • standards “correctly”
    • … is “on” the Web, not tunnelled through it
  • REST is an Architectural Style
    • Defines a set of key “constraints”
    • … that, if met, make an architecture “RESTful”
    • … with the Web as one example
    • Equate “REST” with “RESTful HTTP usage”
    • Stefan Tilkov
  • Deriving REST
    • Client-Server
    • Stateless
    • Cache
    • Uniform interface
    • Layered system
    • Code on Demand
    • “ The central feature that distinguishes the REST architectural style from other network-based styles is its emphasis on a uniform interface between components.”
    • Roy Fielding
  • Uniform Interface
    • Uniform resource identification
    • A set of well-defined operations for manipulation
    • A shared set of media-types
    • Hypertext as the engine of application state
  • Benefits of REST
    • Hypertext is standardized
    • fewer UIs
    • Identification is standardized
    • less communication
    • Exchange protocols are standardized
    • fewer integrations
    • Interactions are standardized
    • fewer semantics
    • Data formats are standardized
    • fewer translations
    • “ No matter how hard I try, I still think the WS-* stack is bloated, opaque, and insanely complex. I think it is going to be hard to understand, hard to implement, hard to interoperate, and hard to secure.”
      • Tim Bray (XML Co-inventor)
    • “ If you’re ready for REST I suggest you jump on board right away and get ahead of the curve
    • You’ll have to train your developers in REST principles.
    • You definitely need to provide guidance to your people.
    • What you want to do is work to the point where REST becomes the default for all your distributed applications.”
      • Anne Thomas Manes (Burton Group)
  •  
    • Links
    • http://del.icio.us/alan.dean/mvc
    • http://thoughtpad.net/alan-dean
    • Email
    • [email_address]
    • © MMVIII