jess chadwick website manager infragistics jesschadwick@gmail com l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
the ASP.NET MVC Framework PowerPoint Presentation
Download Presentation
the ASP.NET MVC Framework

Loading in 2 Seconds...

play fullscreen
1 / 48

the ASP.NET MVC Framework - PowerPoint PPT Presentation


  • 65 Views
  • Uploaded on

Jess Chadwick Website Manager, Infragistics jesschadwick@gmail.com. the ASP.NET MVC Framework. History of Microsoft Web Stuff. The Genealogy of Awesomeness. Active Server Pages. Active Server Pages (ASP). V1 circa 1996 “Active Scripting Pages”: top-down script

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'the ASP.NET MVC Framework' - noel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
jess chadwick website manager infragistics jesschadwick@gmail com
Jess Chadwick

Website Manager, Infragistics

jesschadwick@gmail.com

the ASP.NET MVC Framework

history of microsoft web stuff
History of Microsoft Web Stuff

The Genealogy of Awesomeness

active server pages asp
Active Server Pages (ASP)
  • V1 circa 1996
  • “Active Scripting Pages”: top-down script
  • Call into VB6/COM code to do “real work”
  • You might remember these oldies but goodies:
    • Request object
    • Response object
    • Session object
    • Server object
    • Application object
    • ObjectContext object
    • ASPError object
asp net
ASP.NET
  • Released in 2002 as part of .NET 1.0
    • Not “ASP v.Next” – completely new
  • Introduced a few important concepts:
    • Rich programming framework
    • Code-Behind
    • Page Lifecycle
    • The omnipresent ViewState!
asp net extensions
“ASP.NET Extensions”
  • Started with “ASP.NET Futures”
  • ASP.NET AJAX
  • Silverlight Controls
  • ADO.NET Data Services
  • ASP.NET Dynamic Data

And…

  • ASP.NET MVC!
what is asp net mvc
What is ASP.NET MVC?
  • Microsoft’s ASP.NET implementation of the MVC software pattern
  • More control over your HTML and URLs
  • More easily testable framework
  • A new Web Project type for ASP.NET
  • An option / alternative
demo mvc hello world
DEMO: MVC Hello World

Let’s whet the appetite!

what s the point
What’s the Point?
  • This is not “Web Forms v.Next”
    • All about alternatives
  • Flexibility
    • Extend it… or not
    • Create your own Controller- and ViewEngines, or use others such as Brail or NHaml
  • Fundamental
    • Part of System.Web namespace
    • Fully supported
  • KISS & DRY
driving goals
Driving Goals
  • Separation of Concerns
    • Easy testing & TDD
    • Highly-maintainable applications
  • Extensible and Pluggable
    • Plug in what you need
    • Build your own custom build
driving goals cont d
Driving Goals (cont’d)
  • Clean URLs and HTML
    • SEO and REST friendly
  • Great interaction with ASP.NET
    • Handlers, Modules, Providers, etc. still work
    • .ASPX, .ASCX, .MASTER pages
      • Visual Studio ASP.NET Designer surface
take a look under the hood
Take a Look Under the Hood

Careful – there’s a grease spot over there…

the model
The Model

“The center of the universe” - Todd Snyder

  • This represents your core business domain…AKA – your “bread and butter”
  • Preferably independent of any specific technology
views
Views
  • Are for rendering/output.
  • Are usually pretty “stupid”
  • Web Forms as default ViewEngine
    • .ASPX, .ASCX, .MASTER, etc.
  • Html Helpers for rendering markup
  • Can replace with other view technologies:
    • Template engines (NVelocity, Brail, …).
    • Output formats (images, RSS, JSON, …).
    • Mock out for testing.
  • Can use loosely typed or strongly typed data
controllers
Controllers
  • URLs route to actions on controllers, not pages
  • Controller executes logic, loads data (if any), and chooses view.
  • Can also redirect to other views & URLs

public ActionResultShowPost(int id) {

Post p = PostRepository.GetPostById(id);

if (p == null) {

return RenderView("nosuchpost", id);

} else {

return RenderView(“showpost", p);

}

}

the mvc pattern in action
The MVC Pattern in action
  • Browser makes a request
  • Route is determined
  • Controller is activated
  • Method on Controller is invoked
  • Controller does some stuff
  • Renders View, passing in custom ViewData
      • URLs are rendered, pointing to other Controllers
asp net mvc features
ASP.NET MVC Features

Routing

Filters

Extensibility

View Engines

Controller Factories

Routing Handler

url routing
URL Routing
  • Developers add Routes to a global RouteTable
  • Mapping creates a RouteData - a bag of key/values

RouteTable.Routes.Add(

new Route("blog/bydate/{year}/{month}/{day}", new MvcRouteHandler()){

Defaults = new RouteValueDictionary {

{"controller", "blog"}, {"action", "show"}

},

Constraints = new RouteValueDictionary { {"year", @"\d{1.4}"}, {"month", @"\d{1.2}"},

{"day", @"\d{1.2}"}}

})

demo url routing
Demo: URL Routing

“Can’t you just stop and ask for directions!?”

url routing cont d
URL Routing (cont’d)
  • Separate assembly, not closely tied/related to ASP.NET MVC
filters
Filters
  • Add pre- and post-execute behaviors to your controller actions
  • Useful for logging, compression, etc.

public abstract class ActionFilterAttribute

{

public void OnActionExecuting(ActionExecutingContext context) ;

public void OnActionExecuted(ActionExecutingContext context) ;

// New in Pre-Preview 3:

public void OnResultExecuting(ResultExecutingContext context);

public void OnResultExecuted(ResultExecutedContext context);

}

extensibility
Extensibility
  • Views
  • Controllers
  • Models
  • Routes

…all Pluggable

viewenginebase
ViewEngineBase
  • View Engines render output
  • You get WebForms by default
  • Can implement your own
    • MVCContrib has ones for Brail, Nvelocity
    • NHaml is an interesting one to watch
  • View Engines can be used to
    • Offer new DSLs to make HTML easier
    • Generate totally different mime/types
      • Images, RSS, JSON, XML, OFX, VCards, whatever.
viewenginebase class
ViewEngineBase Class

public abstract class ViewEngineBase {

public abstract void RenderView(ViewContextviewContext);

}

example view web forms
Example View: Web Forms

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true"

CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %>

<asp:ContentContentPlaceHolderID="MainContentPlaceHolder" runat="server">

<h2><%= ViewData.CategoryName %></h2>

<ul>

<% foreach (var product in ViewData.Products) { %>

<li>

<%= product.ProductName %>

<div class="editlink">

(<%= Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })%>)

</div>

</li>

<% } %>

</ul>

<%= Html.ActionLink("Add New Product", new { Action="New" }) %>

</asp:Content>

example view nhaml
Example View: NHaml

%h2= ViewData.CategoryName %ul

- foreach (var product in ViewData.Products) %li = product.ProductName .editlink = Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID }) = Html.ActionLink("Add New Product", new { Action="New" })

demo filters and view engines
Demo: Filters and View Engines

Now we can really take control!

mvccontrib
MVCContrib

Open Source project with extensions to base framework

  • Myriad UI helper extensions and classes
  • View Engines
    • NHaml
    • NVelocity
    • Brail
    • Xslt
  • Controller factories (for IoC)
    • Castle (Windsor)
    • Spring.NET
    • Ninject
    • StructureMap
    • Object Builder
    • Unity

On CodePlex at http://www.codeplex.com/MVCContrib

testability
Testability

“What!? I can mock out HttpContext!?”

designed for testability
Designed for Testability
  • MockableIntrinsics
    • HttpContextBase, HttpResponseBase, HttpRequestBase
  • Extensibility
    • IController
    • IControllerFactory
    • IRouteHandler
    • ViewEngineBase
testing controller actions
Testing Controller Actions
  • No requirement to test within ASP.NET runtime!
    • Use RhinoMocks, TypeMock, Moq, etc.
    • Create Test versions of the parts of the runtime you want to stub

[TestMethod]

public void ShowPostsDisplayPostView() {

TestPostRepository repository = new TestPostRepository();

TestViewEngineviewEngine = new TestViewEngine();

BlogController controller = new BlogController(…);

controller.ShowPost(2);

Assert.AreEqual("showpost",viewEngine.LastRequestedView);

Assert.IsTrue(repository.GetPostByIdWasCalled);

Assert.AreEqual(2, repository.LastRequestedPostId);

}

demo test driven development
DEMO: Test-Driven Development

“Wasn’t this supposed to come first?”

popular questions
Popular Questions

(I know what you’re thinking…)

why reinvent the wheel
Why reinvent the wheel?
  • Aren’t there already existing frameworks out there, such as Monorail?
asp net mvc rest
ASP.NET MVC & REST
  • Does MVC do REST?
    • Depends on your definition. 
  • What about ADO.NET Data Extensions (Astoria) and/or WCF?
controls components
Controls & Components
  • Can still use server controls?
    • Can we still use Web Forms server controls?
  • Decent support for user controls
  • Still more/better support to come
what about ajax
What about AJAX?
  • ASP.NET AJAX?
    • Requires <form runat=“server”>
  • Roll your own
    • JS frameworks like jQuerymake this easier
scalability performance security etc
Scalability, Performance, Security, Etc.
  • A layer of abstraction working over the solid, tested ASP.NET foundation
what s the point46
What’s the Point?
  • This is not “Web Forms v.Next”
    • All about alternatives
  • Flexibility
    • Extend it… or not
    • Create your own Controller- and ViewEngines, or use others such as Brail or NHaml
  • Fundamental
    • Part of System.Web namespace
    • Fully supported
  • KISS & DRY
slide47

Q & A

(…and Thank You!)

resources
Resources

Jess Chadwick

Web Lead

Infragistics, Inc.

jesschadwick@gmail.com

http://blog.jesschadwick.com

  • The Bits
      • ASP.NET MVC Preview 2: http://asp.net/MVC
      • ASP.NET MVC Pre-Preview3: http://www.codeplex.com/aspnet
      • MVCContrib: http://www.codeplex.com/MVCContrib
  • Quickstart
    • http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx
  • Videos
    • ASP.NET: http://www.asp.net/learn/3.5-extensions-videos/
    • MIX: http://sessions.visitmix.com
  • Community/Blogs
      • ASP.NET Forums: http://forums.asp.net/1146.aspx
      • Scott Guthrie (ScottGu): http://weblogs.asp.net/scottgu/
      • Scott Hanselman: http://www.hanselman.com/blog/
      • Phil Haack: http://haacked.com/
    • Sample Apps
      • MVC Samples: http://www.codeplex.com/mvcsamples
      • CodeCampServer: http://codecampserver.org