SlideShare a Scribd company logo
1 of 26
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!

More Related Content

What's hot

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 minEdgar Parada
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentationmanolitto
 
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 architectureMichael He
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day WorkshopShyam 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 startedSté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.5Jon Galloway
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0Nagaraju Sangam
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse 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 projectJadson 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 developersYakov Fain
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJSInfragistics
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slidessamhelman
 

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
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
JavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io PresentationJavaLand 2014 - Ankor.io Presentation
JavaLand 2014 - Ankor.io Presentation
 
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
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
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
 
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)
 
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
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
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
 
Angular js
Angular jsAngular js
Angular js
 
Angular js
Angular jsAngular js
Angular js
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
 

Viewers also liked

Media evaluation Q.1
Media evaluation Q.1Media evaluation Q.1
Media evaluation Q.1phoebeconnie
 
Apresentação Oficial da Youphi
Apresentação Oficial da YouphiApresentação Oficial da Youphi
Apresentação Oficial da YouphiIvan 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 2014hfgedszxfcvb
 
Flat plan
Flat planFlat plan
Flat planLBondi9
 
Weekly Stock Market Tips
Weekly Stock Market TipsWeekly Stock Market Tips
Weekly Stock Market TipsNisha 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. KeenanKelly 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 ArttdinoxRajat Tyagi
 

Viewers also liked (13)

Juego pacman 1
Juego pacman 1Juego pacman 1
Juego pacman 1
 
Media evaluation Q.1
Media evaluation Q.1Media evaluation Q.1
Media evaluation Q.1
 
Apresentação Oficial da Youphi
Apresentação Oficial da YouphiApresentação Oficial da Youphi
Apresentação Oficial da Youphi
 
Auto replies
Auto repliesAuto replies
Auto replies
 
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
 
Felicitacion.
Felicitacion.Felicitacion.
Felicitacion.
 
Flat plan
Flat planFlat plan
Flat plan
 
Weekly Stock Market Tips
Weekly Stock Market TipsWeekly Stock Market Tips
Weekly Stock Market Tips
 
Ask the Prof
Ask the ProfAsk the Prof
Ask the Prof
 
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
 
Wall jobs pitch
Wall jobs pitchWall jobs pitch
Wall jobs pitch
 
Dai Gelinlik
Dai GelinlikDai Gelinlik
Dai Gelinlik
 
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
 

Similar to Hanselman lipton asp_connections_ams304_mvc

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 SawantNitin Sawant
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Patternmaddinapudi
 
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 MVCAnkit Kashyap
 
Play with azure functions
Play with azure functionsPlay with azure functions
Play with azure functionsBaskar 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 5Daniel 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 - VS2015Hossein Zahed
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCBaskar rao Dsn
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaBaskar rao Dsn
 
Era of server less computing
Era of server less computingEra of server less computing
Era of server less computingBaskar rao Dsn
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHPMarcos Quesada
 
Era of server less computing final
Era of server less computing finalEra of server less computing final
Era of server less computing finalBaskar rao Dsn
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 AppFelix 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 NineMvpChalermpon 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 AngularJSGunnar 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 apiYonni 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 #flowVincent 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 FunctionsBIWUG
 

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
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
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
 
Play with azure functions
Play with azure functionsPlay with azure functions
Play with azure functions
 
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
 
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
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCC
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsa
 
Sitecore mvc
Sitecore mvcSitecore mvc
Sitecore mvc
 
Era of server less computing
Era of server less computingEra of server less computing
Era of server less computing
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Era of server less computing final
Era of server less computing finalEra of server less computing final
Era of server less computing final
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
 
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
 
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
 
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
 
#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
 
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
 

Recently uploaded

原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证nhjeo1gg
 
办理老道明大学毕业证成绩单|购买美国ODU文凭证书
办理老道明大学毕业证成绩单|购买美国ODU文凭证书办理老道明大学毕业证成绩单|购买美国ODU文凭证书
办理老道明大学毕业证成绩单|购买美国ODU文凭证书saphesg8
 
Digital Marketing Training Institute in Mohali, India
Digital Marketing Training Institute in Mohali, IndiaDigital Marketing Training Institute in Mohali, India
Digital Marketing Training Institute in Mohali, IndiaDigital Discovery Institute
 
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一lvtagr7
 
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改yuu sss
 
Back on Track: Navigating the Return to Work after Parental Leave
Back on Track: Navigating the Return to Work after Parental LeaveBack on Track: Navigating the Return to Work after Parental Leave
Back on Track: Navigating the Return to Work after Parental LeaveMarharyta Nedzelska
 
Navigating the Data Economy: Transforming Recruitment and Hiring
Navigating the Data Economy: Transforming Recruitment and HiringNavigating the Data Economy: Transforming Recruitment and Hiring
Navigating the Data Economy: Transforming Recruitment and Hiringkaran651042
 
Crack JAG. Guidance program for entry to JAG Dept. & SSB interview
Crack JAG. Guidance program for entry to JAG Dept. & SSB interviewCrack JAG. Guidance program for entry to JAG Dept. & SSB interview
Crack JAG. Guidance program for entry to JAG Dept. & SSB interviewNilendra Kumar
 
Ioannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfIoannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfjtzach
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of JobRemote DBA Services
 
办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书saphesg8
 
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一diploma 1
 
LinkedIn Strategic Guidelines April 2024
LinkedIn Strategic Guidelines April 2024LinkedIn Strategic Guidelines April 2024
LinkedIn Strategic Guidelines April 2024Bruce Bennett
 
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一z xss
 
tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...vinbld123
 
Issues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxIssues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxJenniferPeraro1
 
MIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewMIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewSheldon Byron
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012sapnasaifi408
 

Recently uploaded (20)

原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
 
办理老道明大学毕业证成绩单|购买美国ODU文凭证书
办理老道明大学毕业证成绩单|购买美国ODU文凭证书办理老道明大学毕业证成绩单|购买美国ODU文凭证书
办理老道明大学毕业证成绩单|购买美国ODU文凭证书
 
Digital Marketing Training Institute in Mohali, India
Digital Marketing Training Institute in Mohali, IndiaDigital Marketing Training Institute in Mohali, India
Digital Marketing Training Institute in Mohali, India
 
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档
格里菲斯大学毕业证(Griffith毕业证)#文凭成绩单#真实留信学历认证永久存档
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
 
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改
办澳洲詹姆斯库克大学毕业证成绩单pdf电子版制作修改
 
Back on Track: Navigating the Return to Work after Parental Leave
Back on Track: Navigating the Return to Work after Parental LeaveBack on Track: Navigating the Return to Work after Parental Leave
Back on Track: Navigating the Return to Work after Parental Leave
 
Navigating the Data Economy: Transforming Recruitment and Hiring
Navigating the Data Economy: Transforming Recruitment and HiringNavigating the Data Economy: Transforming Recruitment and Hiring
Navigating the Data Economy: Transforming Recruitment and Hiring
 
Crack JAG. Guidance program for entry to JAG Dept. & SSB interview
Crack JAG. Guidance program for entry to JAG Dept. & SSB interviewCrack JAG. Guidance program for entry to JAG Dept. & SSB interview
Crack JAG. Guidance program for entry to JAG Dept. & SSB interview
 
Ioannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfIoannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdf
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Job
 
办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书
 
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一
办理(Salford毕业证书)索尔福德大学毕业证成绩单原版一比一
 
LinkedIn Strategic Guidelines April 2024
LinkedIn Strategic Guidelines April 2024LinkedIn Strategic Guidelines April 2024
LinkedIn Strategic Guidelines April 2024
 
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一
定制(SCU毕业证书)南十字星大学毕业证成绩单原版一比一
 
tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...
 
Issues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxIssues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptx
 
MIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewMIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx review
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
 
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort ServiceYoung Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
Young Call~Girl in Pragati Maidan New Delhi 8448380779 Full Enjoy Escort Service
 

Hanselman lipton asp_connections_ams304_mvc

  • 1. AMS304: Introduction to the ASP.NET Model View Controller (MVC) Framework Scott Hanselman Eilon Lipton Microsoft Microsoft scottha@microsoft.com elipton@microsoft.com
  • 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

  1. Been around since Xerox in 1979
  2. Been around since Xerox in 1979
  3. Been around since Xerox in 1979
  4. Write a blog
  5. Write a blog
  6. Write a blog
  7. Write a blog
  8. Write a blog
  9. Write a blog