SlideShare a Scribd company logo
AMS304: Introduction to the
ASP.NET Model View Controller
     (MVC) Framework
Scott Hanselman         Eilon Lipton
   Microsoft              Microsoft
scottha@microsoft.com   elipton@microsoft.com
MVC

INTRO
Goodness

• Maintain Clean Separation of Concerns
  ●   Easy Testing
  ●   Red/Green TDD
  ●   Highly maintainable applications by default
• Extensible and Pluggable
  ●   Support replacing any component of the
      system
Goodness

• Enable clean URLs and HTML
  ●   SEO and REST friendly URL structures

• Great integration within ASP.NET
  ●   Support both static and dynamic languages
What’s the Point?

• This is not Web Forms 4.0
  ●   It’s about alternatives. Car vs. Motorcycle.
• Simple or as complex as you like
  ●   Extend it, add IOC. Or not. If the shoe pinches, don’t
      wear it.
• Fundamental
  ●   Part of System.Web and isn’t going anywhere.
• Plays Well With Others
  ●   Feel free to use NHibernate for Models, Brail for
      Views and Whatever for Controllers. Be Happy.
MVC


             Model




      View           Controller
A Little More Detail

                      •Browser requests /Products/
                      •Route is determined
         Model        •Controller is activated
                      •Method on Controller is invoke
                      •Controller does some stuff
                      •Renders View, passing in
                            custom ViewData
                             •URLs are rendered,
                              pointing to other
  View           Controller   Controllers
Even More Detail – Request Flow
Request    • You can futz at each step
             in the process


 URL       Http
Routing               Controller   Response
          Handler




           Route       View
 Route                               View
          Handler     Factory
Demo – Hello MVC World

  Don’t fall asleep, it’ll be worth it.
MVC

HOW IT WORKS
Basic Controller Handling

• Scenarios, Goals and Design
  ●   URLs route to controller “actions”, not pages –
      mark actions in Controller.
  ●   Controller executes logic, chooses view.
  [ControllerAction]
 public void ShowPost(int id) {
      Post p = PostRepository.GetPostById(id);
      if (p != null) {
          RenderView("showpost", p);
      } else {
          RenderView("nosuchpost", id);
      }
}
Basic Views

• Scenarios, Goals and Design:
  ●   Are for rendering/output.
       • Pre-defined and extensible rendering helpers
  ●   Can use .ASPX, .ASCX, .MASTER, etc.
  ●   Can replace with other view technologies:
       • Template engines (NVelocity, Brail, …).
       • Output formats (images, RSS, JSON, …).
       • Mock out for testing.
  ●   Controller sets data on the View
       • Loosely typed or strongly typed data
URL Routing – Pretty URIs
    • Developers adds Routes to a global RouteTable
    • Mapping creates a RouteData - a bag of key/values
protected void Application_Start(object sender, EventArgs e)
{

RouteTable.Routes.Add(new Route {
  Url = "Blog/bydate/[year]/[month]/[day]",
  Defaults = new { controller="blog", action="showposts" },
  Validation = new { year=@"d{1,4}", month= @"d{1,2}",
                       day = @"d{1,2}"} });

RouteTable.Routes.Add(new Route {
  Url = "[controller]/[action]/[id]",
  RouteHandler = typeof(MvcRouteHandler) });

}
Demo – Routing

    The route less travelled…
MVC

HOW TO TEST IT
Interfaces and TDD

• Mockable Intrinsics
  ●   IHttpContext, IHttpResponse, IHttpRequest
• Extensibility
  ●   IController
  ●   IControllerFactory
  ●   IRouteHandler
  ●   IView
  ●   IViewFactory
Testing Controller Actions
• No requirement to mock out full ASP.NET runtime.
[TestMethod]
public void ShowPostsDisplayPostView() {
    TestPostRepository repository = new TestPostRepository();
    TestViewFactory viewFactory = new TestViewFactory();

    BlogController controller = new BlogController(…);
    controller.ShowPost(2);

    Assert.AreEqual("showpost", viewFactory.LastRequestedView);
    Assert.IsTrue(repository.GetPostByIdWasCalled);
    Assert.AreEqual(2, repository.LastRequestedPostId);
}
Controller Factory
• Scenarios, Goals and Design:
   ●   Hook creation of controller instance
        • Dependency Injection.
        • Object Interception.

public interface IControllerFactory {
    IController CreateController(IHttpContext context,
         RouteData routeData,
         Type controllerType);
}

protected void Application_Start(object s, EventArgs e) {
  ControllerBuilder.Current.SetDefaultControllerFactory(
    typeof(MyControllerFactory));
}
View Factory
• Scenarios, Goals and Design:
   ●   Mock out views for testing
   ●   Replace ASPX with other technologies
public interface IViewFactory {
    IView CreateView(IHttpContext context,
        RouteData routeData,
        string viewName, string layoutName,
        object viewData);
}

Inside controller class:
    ViewFactory = new XmlViewFactory(...);

   RenderView("foo", myData);
Demo – TDD

   Wasn’t this demo technically
     supposed to be first?
Demo – Dynamic Data
       Controls
     Not DDE. Scared you, didn’t I?
Demo – ImageGen

        It’s your thing.
    Do what you wanna do.
Demo – Ruby View Engine
& Python Controller
   It’s a kinder, gentler Microsoft.
          No seriously. Hug?
Demo – XML-RPC

     SOAP is for dorks.
Conclusion

• This is not Web Forms 4.0
  ●   It’s about alternatives. Car vs. Motorcycle.
• Simple or as complex as you like
  ●   Extend it, add IOC. Or not. If the shoe pinches, don’t
      wear it.
• Fundamental
  ●   Part of System.Web and isn’t going anywhere.
• Plays Well With Others
  ●   Feel free to use NHibernate for Models, Brail for
      Views and VB for Controllers. Be Happy.
Your Feedback is Important

Please fill out a session evaluation form and
  either put them in the basket near the exit
      or drop them off at the conference
                registration desk.

                Thank you!
Ad

More Related Content

What's hot (20)

Everything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 minEverything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
Jayantha Sirisena
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentation
manolitto
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
Michael He
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
Shyam Seshadri
 
Angular js
Angular jsAngular js
Angular js
yogi_solanki
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
Santhosh Kumar Srinivasan
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju Sangam
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
Jesse Warden
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular js
Angular jsAngular js
Angular js
Manav Prasad
 
Angular js
Angular jsAngular js
Angular js
Hritesh Saha
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
Yakov Fain
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
Infragistics
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
samhelman
 
Everything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 minEverything you need to know about HTML5 in 15 min
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentation
manolitto
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
Michael He
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
Shyam Seshadri
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju Sangam
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
Jesse Warden
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
Yakov Fain
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
Infragistics
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
samhelman
 

Viewers also liked (13)

Juego pacman 1
Juego pacman 1Juego pacman 1
Juego pacman 1
Daniel Murillo Suarez
 
Media evaluation Q.1
Media evaluation Q.1Media evaluation Q.1
Media evaluation Q.1
phoebeconnie
 
Apresentação Oficial da Youphi
Apresentação Oficial da YouphiApresentação Oficial da Youphi
Apresentação Oficial da Youphi
Ivan Caixeta
 
Auto replies
Auto repliesAuto replies
Auto replies
caitlinmurray123
 
An+ülisis de un mensaje individual 2014
An+ülisis de un mensaje individual 2014An+ülisis de un mensaje individual 2014
An+ülisis de un mensaje individual 2014
hfgedszxfcvb
 
Felicitacion.
Felicitacion.Felicitacion.
Felicitacion.
Carlos Rodriguez Barragan
 
Flat plan
Flat planFlat plan
Flat plan
LBondi9
 
Weekly Stock Market Tips
Weekly Stock Market TipsWeekly Stock Market Tips
Weekly Stock Market Tips
Nisha Sharma
 
Ask the Prof
Ask the ProfAsk the Prof
Ask the Prof
Del Williams
 
Kelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes Edu 105 June 22, 2015 Dr. KeenanKelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes
 
Wall jobs pitch
Wall jobs pitchWall jobs pitch
Wall jobs pitch
Henrique Calandra
 
Dai Gelinlik
Dai GelinlikDai Gelinlik
Dai Gelinlik
Dai Kurhan
 
Customized Stainless Steel Modular Kitchens by Arttdinox
Customized Stainless Steel Modular Kitchens by ArttdinoxCustomized Stainless Steel Modular Kitchens by Arttdinox
Customized Stainless Steel Modular Kitchens by Arttdinox
Rajat Tyagi
 
Media evaluation Q.1
Media evaluation Q.1Media evaluation Q.1
Media evaluation Q.1
phoebeconnie
 
Apresentação Oficial da Youphi
Apresentação Oficial da YouphiApresentação Oficial da Youphi
Apresentação Oficial da Youphi
Ivan Caixeta
 
An+ülisis de un mensaje individual 2014
An+ülisis de un mensaje individual 2014An+ülisis de un mensaje individual 2014
An+ülisis de un mensaje individual 2014
hfgedszxfcvb
 
Flat plan
Flat planFlat plan
Flat plan
LBondi9
 
Weekly Stock Market Tips
Weekly Stock Market TipsWeekly Stock Market Tips
Weekly Stock Market Tips
Nisha Sharma
 
Kelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes Edu 105 June 22, 2015 Dr. KeenanKelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes Edu 105 June 22, 2015 Dr. Keenan
Kelly Briddes
 
Customized Stainless Steel Modular Kitchens by Arttdinox
Customized Stainless Steel Modular Kitchens by ArttdinoxCustomized Stainless Steel Modular Kitchens by Arttdinox
Customized Stainless Steel Modular Kitchens by Arttdinox
Rajat Tyagi
 
Ad

Similar to Hanselman lipton asp_connections_ams304_mvc (20)

Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
maddinapudi
 
Fast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCFast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVC
Ankit Kashyap
 
Play with azure functions
Play with azure functionsPlay with azure functions
Play with azure functions
Baskar rao Dsn
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCC
Baskar rao Dsn
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsa
Baskar rao Dsn
 
Sitecore mvc
Sitecore mvcSitecore mvc
Sitecore mvc
pratik satikunvar
 
Era of server less computing
Era of server less computingEra of server less computing
Era of server less computing
Baskar rao Dsn
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
Marcos Quesada
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
murtazahaveliwala
 
Era of server less computing final
Era of server less computing finalEra of server less computing final
Era of server less computing final
Baskar rao Dsn
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
Felix Gessert
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Chalermpon Areepong
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Automating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server apiAutomating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server api
Yonni Mendes
 
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
Vincent Biret
 
Introduction to Microsoft Flow and Azure Functions
Introduction to Microsoft Flow and Azure FunctionsIntroduction to Microsoft Flow and Azure Functions
Introduction to Microsoft Flow and Azure Functions
BIWUG
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
maddinapudi
 
Fast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCFast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVC
Ankit Kashyap
 
Play with azure functions
Play with azure functionsPlay with azure functions
Play with azure functions
Baskar rao Dsn
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCC
Baskar rao Dsn
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsa
Baskar rao Dsn
 
Era of server less computing
Era of server less computingEra of server less computing
Era of server less computing
Baskar rao Dsn
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
Marcos Quesada
 
Era of server less computing final
Era of server less computing finalEra of server less computing final
Era of server less computing final
Baskar rao Dsn
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
Felix Gessert
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Chalermpon Areepong
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Automating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server apiAutomating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server api
Yonni Mendes
 
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
#SPSBrussels 2017 vincent biret #azure #functions microsoft #flow
Vincent Biret
 
Introduction to Microsoft Flow and Azure Functions
Introduction to Microsoft Flow and Azure FunctionsIntroduction to Microsoft Flow and Azure Functions
Introduction to Microsoft Flow and Azure Functions
BIWUG
 
Ad

Recently uploaded (20)

Sample animal revalidation protocol for resaecrh based.pptx
Sample animal revalidation protocol for resaecrh based.pptxSample animal revalidation protocol for resaecrh based.pptx
Sample animal revalidation protocol for resaecrh based.pptx
azeemccras
 
Employment Communication : The Job HUnting.pptx
Employment Communication : The Job HUnting.pptxEmployment Communication : The Job HUnting.pptx
Employment Communication : The Job HUnting.pptx
JunaidAlvi5
 
SAFETY BRIEFING.........................
SAFETY BRIEFING.........................SAFETY BRIEFING.........................
SAFETY BRIEFING.........................
BalaChandran458212
 
HCollege ppt guidance and counselin.pptx
HCollege ppt guidance and counselin.pptxHCollege ppt guidance and counselin.pptx
HCollege ppt guidance and counselin.pptx
liajohn0808
 
Introduction on Speaking skills Power Point
Introduction on Speaking skills Power PointIntroduction on Speaking skills Power Point
Introduction on Speaking skills Power Point
helenswarna
 
RightShip-Inspection-Maritime-Safety-Simplified.pptx
RightShip-Inspection-Maritime-Safety-Simplified.pptxRightShip-Inspection-Maritime-Safety-Simplified.pptx
RightShip-Inspection-Maritime-Safety-Simplified.pptx
ultronmeg
 
Best Fashion Designing Colleges in Delhi
Best Fashion Designing Colleges in DelhiBest Fashion Designing Colleges in Delhi
Best Fashion Designing Colleges in Delhi
top10privatecolleges
 
Career Planning After Class XII: Your Roadmap to Success
Career Planning After Class XII: Your Roadmap to SuccessCareer Planning After Class XII: Your Roadmap to Success
Career Planning After Class XII: Your Roadmap to Success
Dr. Radhika Sharma
 
GENERAL INFORMATION for the most beautiful
GENERAL INFORMATION for the most beautifulGENERAL INFORMATION for the most beautiful
GENERAL INFORMATION for the most beautiful
12213013
 
sorcesofdrugs-160228074 56 4246643544 (3).ppt
sorcesofdrugs-160228074 56 4246643544 (3).pptsorcesofdrugs-160228074 56 4246643544 (3).ppt
sorcesofdrugs-160228074 56 4246643544 (3).ppt
IndalSatnami
 
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptxSHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
ArshjotSingh30
 
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
shenleighmaemolina
 
Top Business Schools in Delhi For Quality Education
Top Business Schools in Delhi For Quality EducationTop Business Schools in Delhi For Quality Education
Top Business Schools in Delhi For Quality Education
top10privatecolleges
 
Stakeholders Management GT 11052021.cleaned.pptx
Stakeholders Management GT 11052021.cleaned.pptxStakeholders Management GT 11052021.cleaned.pptx
Stakeholders Management GT 11052021.cleaned.pptx
SaranshJeena
 
Green Colorful House Simple Illustration Presentation.pdf.pdf
Green Colorful House Simple Illustration Presentation.pdf.pdfGreen Colorful House Simple Illustration Presentation.pdf.pdf
Green Colorful House Simple Illustration Presentation.pdf.pdf
RhyzCharmSolis
 
When Is the Best Time to Use Job Finding Apps?
When Is the Best Time to Use Job Finding Apps?When Is the Best Time to Use Job Finding Apps?
When Is the Best Time to Use Job Finding Apps?
SnapJob
 
!Warshauer Paul Curriculum Vitae, Resume
!Warshauer Paul Curriculum Vitae, Resume!Warshauer Paul Curriculum Vitae, Resume
!Warshauer Paul Curriculum Vitae, Resume
PaulWarshauer1
 
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaauScience Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
atifkhan990367
 
Huckel_Molecular orbital _Theory_8_Slides.pptx
Huckel_Molecular orbital _Theory_8_Slides.pptxHuckel_Molecular orbital _Theory_8_Slides.pptx
Huckel_Molecular orbital _Theory_8_Slides.pptx
study2022bsc
 
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdfLCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
rafaelsago2015
 
Sample animal revalidation protocol for resaecrh based.pptx
Sample animal revalidation protocol for resaecrh based.pptxSample animal revalidation protocol for resaecrh based.pptx
Sample animal revalidation protocol for resaecrh based.pptx
azeemccras
 
Employment Communication : The Job HUnting.pptx
Employment Communication : The Job HUnting.pptxEmployment Communication : The Job HUnting.pptx
Employment Communication : The Job HUnting.pptx
JunaidAlvi5
 
SAFETY BRIEFING.........................
SAFETY BRIEFING.........................SAFETY BRIEFING.........................
SAFETY BRIEFING.........................
BalaChandran458212
 
HCollege ppt guidance and counselin.pptx
HCollege ppt guidance and counselin.pptxHCollege ppt guidance and counselin.pptx
HCollege ppt guidance and counselin.pptx
liajohn0808
 
Introduction on Speaking skills Power Point
Introduction on Speaking skills Power PointIntroduction on Speaking skills Power Point
Introduction on Speaking skills Power Point
helenswarna
 
RightShip-Inspection-Maritime-Safety-Simplified.pptx
RightShip-Inspection-Maritime-Safety-Simplified.pptxRightShip-Inspection-Maritime-Safety-Simplified.pptx
RightShip-Inspection-Maritime-Safety-Simplified.pptx
ultronmeg
 
Best Fashion Designing Colleges in Delhi
Best Fashion Designing Colleges in DelhiBest Fashion Designing Colleges in Delhi
Best Fashion Designing Colleges in Delhi
top10privatecolleges
 
Career Planning After Class XII: Your Roadmap to Success
Career Planning After Class XII: Your Roadmap to SuccessCareer Planning After Class XII: Your Roadmap to Success
Career Planning After Class XII: Your Roadmap to Success
Dr. Radhika Sharma
 
GENERAL INFORMATION for the most beautiful
GENERAL INFORMATION for the most beautifulGENERAL INFORMATION for the most beautiful
GENERAL INFORMATION for the most beautiful
12213013
 
sorcesofdrugs-160228074 56 4246643544 (3).ppt
sorcesofdrugs-160228074 56 4246643544 (3).pptsorcesofdrugs-160228074 56 4246643544 (3).ppt
sorcesofdrugs-160228074 56 4246643544 (3).ppt
IndalSatnami
 
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptxSHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
SHIPPING CONTAINdccdcdERS BC (2).pdf.pptx
ArshjotSingh30
 
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
What's the Volume Quiz Presentation in Green Grey Purple Simple Lined Style (...
shenleighmaemolina
 
Top Business Schools in Delhi For Quality Education
Top Business Schools in Delhi For Quality EducationTop Business Schools in Delhi For Quality Education
Top Business Schools in Delhi For Quality Education
top10privatecolleges
 
Stakeholders Management GT 11052021.cleaned.pptx
Stakeholders Management GT 11052021.cleaned.pptxStakeholders Management GT 11052021.cleaned.pptx
Stakeholders Management GT 11052021.cleaned.pptx
SaranshJeena
 
Green Colorful House Simple Illustration Presentation.pdf.pdf
Green Colorful House Simple Illustration Presentation.pdf.pdfGreen Colorful House Simple Illustration Presentation.pdf.pdf
Green Colorful House Simple Illustration Presentation.pdf.pdf
RhyzCharmSolis
 
When Is the Best Time to Use Job Finding Apps?
When Is the Best Time to Use Job Finding Apps?When Is the Best Time to Use Job Finding Apps?
When Is the Best Time to Use Job Finding Apps?
SnapJob
 
!Warshauer Paul Curriculum Vitae, Resume
!Warshauer Paul Curriculum Vitae, Resume!Warshauer Paul Curriculum Vitae, Resume
!Warshauer Paul Curriculum Vitae, Resume
PaulWarshauer1
 
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaauScience Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
Science Lab Safety PPT.pptxwgyie ulbyaaaaaaaaaaaaaaaaaaaaaau
atifkhan990367
 
Huckel_Molecular orbital _Theory_8_Slides.pptx
Huckel_Molecular orbital _Theory_8_Slides.pptxHuckel_Molecular orbital _Theory_8_Slides.pptx
Huckel_Molecular orbital _Theory_8_Slides.pptx
study2022bsc
 
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdfLCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
LCL216_2024-2_WEEKS 4 & 5_IF CLAUSES (1).pdf
rafaelsago2015
 

Hanselman lipton asp_connections_ams304_mvc

  • 1. AMS304: Introduction to the ASP.NET Model View Controller (MVC) Framework Scott Hanselman Eilon Lipton Microsoft Microsoft [email protected] [email protected]
  • 3. Goodness • Maintain Clean Separation of Concerns ● Easy Testing ● Red/Green TDD ● Highly maintainable applications by default • Extensible and Pluggable ● Support replacing any component of the system
  • 4. Goodness • Enable clean URLs and HTML ● SEO and REST friendly URL structures • Great integration within ASP.NET ● Support both static and dynamic languages
  • 5. What’s the Point? • This is not Web Forms 4.0 ● It’s about alternatives. Car vs. Motorcycle. • Simple or as complex as you like ● Extend it, add IOC. Or not. If the shoe pinches, don’t wear it. • Fundamental ● Part of System.Web and isn’t going anywhere. • Plays Well With Others ● Feel free to use NHibernate for Models, Brail for Views and Whatever for Controllers. Be Happy.
  • 6. MVC Model View Controller
  • 7. A Little More Detail •Browser requests /Products/ •Route is determined Model •Controller is activated •Method on Controller is invoke •Controller does some stuff •Renders View, passing in custom ViewData •URLs are rendered, pointing to other View Controller Controllers
  • 8. Even More Detail – Request Flow Request • You can futz at each step in the process URL Http Routing Controller Response Handler Route View Route View Handler Factory
  • 9. Demo – Hello MVC World Don’t fall asleep, it’ll be worth it.
  • 11. Basic Controller Handling • Scenarios, Goals and Design ● URLs route to controller “actions”, not pages – mark actions in Controller. ● Controller executes logic, chooses view. [ControllerAction] public void ShowPost(int id) { Post p = PostRepository.GetPostById(id); if (p != null) { RenderView("showpost", p); } else { RenderView("nosuchpost", id); } }
  • 12. Basic Views • Scenarios, Goals and Design: ● Are for rendering/output. • Pre-defined and extensible rendering helpers ● Can use .ASPX, .ASCX, .MASTER, etc. ● Can replace with other view technologies: • Template engines (NVelocity, Brail, …). • Output formats (images, RSS, JSON, …). • Mock out for testing. ● Controller sets data on the View • Loosely typed or strongly typed data
  • 13. URL Routing – Pretty URIs • Developers adds Routes to a global RouteTable • Mapping creates a RouteData - a bag of key/values protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.Add(new Route { Url = "Blog/bydate/[year]/[month]/[day]", Defaults = new { controller="blog", action="showposts" }, Validation = new { year=@"d{1,4}", month= @"d{1,2}", day = @"d{1,2}"} }); RouteTable.Routes.Add(new Route { Url = "[controller]/[action]/[id]", RouteHandler = typeof(MvcRouteHandler) }); }
  • 14. Demo – Routing The route less travelled…
  • 16. Interfaces and TDD • Mockable Intrinsics ● IHttpContext, IHttpResponse, IHttpRequest • Extensibility ● IController ● IControllerFactory ● IRouteHandler ● IView ● IViewFactory
  • 17. Testing Controller Actions • No requirement to mock out full ASP.NET runtime. [TestMethod] public void ShowPostsDisplayPostView() { TestPostRepository repository = new TestPostRepository(); TestViewFactory viewFactory = new TestViewFactory(); BlogController controller = new BlogController(…); controller.ShowPost(2); Assert.AreEqual("showpost", viewFactory.LastRequestedView); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId); }
  • 18. Controller Factory • Scenarios, Goals and Design: ● Hook creation of controller instance • Dependency Injection. • Object Interception. public interface IControllerFactory { IController CreateController(IHttpContext context, RouteData routeData, Type controllerType); } protected void Application_Start(object s, EventArgs e) { ControllerBuilder.Current.SetDefaultControllerFactory( typeof(MyControllerFactory)); }
  • 19. View Factory • Scenarios, Goals and Design: ● Mock out views for testing ● Replace ASPX with other technologies public interface IViewFactory { IView CreateView(IHttpContext context, RouteData routeData, string viewName, string layoutName, object viewData); } Inside controller class: ViewFactory = new XmlViewFactory(...); RenderView("foo", myData);
  • 20. Demo – TDD Wasn’t this demo technically supposed to be first?
  • 21. Demo – Dynamic Data Controls Not DDE. Scared you, didn’t I?
  • 22. Demo – ImageGen It’s your thing. Do what you wanna do.
  • 23. Demo – Ruby View Engine & Python Controller It’s a kinder, gentler Microsoft. No seriously. Hug?
  • 24. Demo – XML-RPC SOAP is for dorks.
  • 25. Conclusion • This is not Web Forms 4.0 ● It’s about alternatives. Car vs. Motorcycle. • Simple or as complex as you like ● Extend it, add IOC. Or not. If the shoe pinches, don’t wear it. • Fundamental ● Part of System.Web and isn’t going anywhere. • Plays Well With Others ● Feel free to use NHibernate for Models, Brail for Views and VB for Controllers. Be Happy.
  • 26. Your Feedback is Important Please fill out a session evaluation form and either put them in the basket near the exit or drop them off at the conference registration desk. Thank you!

Editor's Notes

  • #7: Been around since Xerox in 1979
  • #8: Been around since Xerox in 1979
  • #9: Been around since Xerox in 1979
  • #15: Write a blog
  • #21: Write a blog
  • #22: Write a blog
  • #23: Write a blog
  • #24: Write a blog
  • #25: Write a blog