SlideShare una empresa de Scribd logo
1 de 61
Web Development
     with
 ASP.NET MVC
         Aaron Lerch
   Development Team Lead
    Interactive Intelligence
• The MVC Pattern
• MVC in ASP.NET
• Testability
• AJAX
The MVC Pattern

             VIEW




CONTROLLER          MODEL
The MVC Pattern

             VIEW




CONTROLLER          MODEL
What is the Model?
   • Domain Objects
   • Data Transfer Objects
   • “Business Logic”
What is the Model?
     • Domain Objects
     • Data Transfer Objects
     • “Business Logic”
      public class Person { }
    public class PersonDTO { }

Repository<Person>.Load(personId)
  MessageService.Send(message)
What is the View?

 • Format the Model
 • Render a display
 • Enable selecting of Actions
What is the Controller?

   • Expose and Respond to Actions
   • Manipulate Model
   • Choose a View
MVC in ASP.NET
Acts like a
12 year old    Is a 12 year old
                                  20-something
Acts like a
12 year old    Is a 12 year old
                                  20-something
HTTP
Client          Server
HTTP
Client                            Server


         GET /foo.html HTTP 1.1
HTTP
Client                                              Server


         GET /foo.html HTTP 1.1


                 200 OK
              Content-Type: application/xhtml+xml
              <html>
                <body>Foo</body>
              </html>
HTTP
Client          Server
HTTP
Client                            Server
         GET /foo.html HTTP 1.1
HTTP
Client                                               Server
         GET /foo.html HTTP 1.1

                   302 Found
          Location: http://www.foobar.com/bar.html
HTTP
Client                                               Server
         GET /foo.html HTTP 1.1

                   302 Found
          Location: http://www.foobar.com/bar.html
HTTP
Client                                               Server
         GET /foo.html HTTP 1.1

                   302 Found
          Location: http://www.foobar.com/bar.html



         GET /bar.html HTTP 1.1
HTTP
Client                                               Server
         GET /foo.html HTTP 1.1

                   302 Found
          Location: http://www.foobar.com/bar.html



         GET /bar.html HTTP 1.1
                      200 OK
                   <html>
                     <body>Bar</body>
                   </html>
ASP.NET
Client             Server
ASP.NET
Client                            Server
         GET /foo.aspx HTTP 1.1
ASP.NET
Client                            Server
         GET /foo.aspx HTTP 1.1      Init
                                     Load
                                     Render
ASP.NET
Client                                  Server
         GET /foo.aspx HTTP 1.1            Init
                                           Load
                 200 OK                    Render
             <form>[VIEWSTATE]</form>
ASP.NET
Client                                   Server
         GET /foo.aspx HTTP 1.1             Init
                                            Load
                  200 OK                    Render
              <form>[VIEWSTATE]</form>

         POST /foo.aspx HTTP 1.1
ASP.NET
Client                                   Server
         GET /foo.aspx HTTP 1.1             Init
                                            Load
                  200 OK                    Render
              <form>[VIEWSTATE]</form>

         POST /foo.aspx HTTP 1.1            Init
                                            Load
                                                LinkClicked
                                                   Redirect
                                            Render
ASP.NET
Client                                                Server
         GET /foo.aspx HTTP 1.1                          Init
                                                         Load
                       200 OK                            Render
                 <form>[VIEWSTATE]</form>

         POST /foo.aspx HTTP 1.1                         Init
                                                         Load
                                                             LinkClicked
                                                                Redirect
                    302 Found                            Render
           Location: http://www.foobar.com/bar.aspx
ASP.NET
Client                                                Server
         GET /foo.aspx HTTP 1.1                          Init
                                                         Load
                       200 OK                            Render
                 <form>[VIEWSTATE]</form>

         POST /foo.aspx HTTP 1.1                         Init
                                                         Load
                                                             LinkClicked
                                                                Redirect
                    302 Found                            Render
           Location: http://www.foobar.com/bar.aspx

         GET /bar.aspx HTTP 1.1
ASP.NET MVC
Client                 Server
ASP.NET MVC
Client                           Server

         GET /foo/bar HTTP 1.1
ASP.NET MVC
Client                           Server

         GET /foo/bar HTTP 1.1
                                    FooController.Bar()
                                       View(“Bar”)
ASP.NET MVC
Client                           Server

         GET /foo/bar HTTP 1.1
                                    FooController.Bar()
                                       View(“Bar”)
               200 OK
ASP.NET MVC
Client                           Server

         GET /foo/bar HTTP 1.1
                                    FooController.Bar()
                                       View(“Bar”)
               200 OK
ASP.NET MVC
Client                             Server

         GET /foo/bar HTTP 1.1
                                      FooController.Bar()
                                         View(“Bar”)
                200 OK

         GET /foos/ball HTTP 1.1
ASP.NET MVC
Client                             Server

         GET /foo/bar HTTP 1.1
                                      FooController.Bar()
                                         View(“Bar”)
                200 OK

         GET /foos/ball HTTP 1.1
                                      FoosController.Ball()
                                         View(“Ball”)
ASP.NET MVC
Client                             Server

         GET /foo/bar HTTP 1.1
                                      FooController.Bar()
                                         View(“Bar”)
                200 OK

         GET /foos/ball HTTP 1.1
                                      FoosController.Ball()
                                         View(“Ball”)
                200 OK
Request Flow
Request




 URL        Http
                     Controller   Response
Routing    Handler




            Route      View
 Route                              View
           Handler    Factory
CODE!
View Engines
<table>
   <% foreach (ScheduleListing listing in schedule)
   { %>
   <tr>
      <td>
         <%=listing.StartTime %> - <%=listing.EndTime %><br />
         <%= listing.Purpose %>
      </td>
      <% foreach (TrackListing track in tracks)
      { %>
      <td>
         <% SessionListing session = listing[track];
         if (session != null)
         { %>
             <%= session.Title%><br />
             (<%= session.Speaker.DisplayName%>)
         <% } else { %>
         <i>None</i>
         <% } %>
      </td>
      <% } %>
   </tr>
   <% } %>
</table>
NHaml
#foo
       - foreach (var product in ViewData)
           - if (product.Category.CategoryName != null)
               %h2=product.Category.CategoryName
               - break
       %ul.productlist
           - foreach (var product in ViewData)
               %li
                   = Html.Image(quot;/Content/Images/quot; + product.ProductID + quot;.jpgquot;, product.ProductName)
                   .productdetail
                       =Html.ActionLink(product.ProductName, quot;Detailquot;, new { ID=product.ProductID })
                       %br
                       Price:
                       =String.Format(quot;{0:C2}quot;, product.UnitPrice)
                           %span.editlink
                               (
                               =Html.ActionLink(quot;Editquot;, quot;Editquot;, new { ID=product.ProductID })
                               )
NHaml
#foo
       - foreach (var product in ViewData)
           - if (product.Category.CategoryName != null)
               %h2=product.Category.CategoryName
               - break
       %ul.productlist
           - foreach (var product in ViewData)
               %li
                   = Html.Image(quot;/Content/Images/quot; + product.ProductID + quot;.jpgquot;, product.ProductName)
                   .productdetail
                       =Html.ActionLink(product.ProductName, quot;Detailquot;, new { ID=product.ProductID })
                       %br
                       Price:

                                            “.productdetail”
                       =String.Format(quot;{0:C2}quot;, product.UnitPrice)
                           %span.editlink
                               (
                               =Html.ActionLink(quot;Editquot;, quot;Editquot;, new { ID=product.ProductID })
                               )                      becomes

                                    <div id=”productdetail”>
Spark
<ul class=quot;productlistquot;>
 <var styles='new[] {quot;oddquot;, quot;evenquot;}'/>
 <li each=quot;var product in ViewData.Modelquot; class=quot;${styles[productIndex%2]}quot;>
   <ProductImage style='quot;float:left;quot;'/>
   <p>
   <a href=quot;/Products/Detail/${product.ProductID}quot;>${product.ProductName}</a>
   <br />
   Price: ${String.Format(quot;{0:C2}quot;, product.UnitPrice)}
   <span class=quot;editlinkquot;>
   (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), quot;Editquot;)})
   </span>
   </p>
   <div style=quot;clear:both;quot;></div>
 </li>
</ul>
Spark
<ul class=quot;productlistquot;>
 <var styles='new[] {quot;oddquot;, quot;evenquot;}'/>
 <li each=quot;var product in ViewData.Modelquot; class=quot;${styles[productIndex%2]}quot;>
   <ProductImage style='quot;float:left;quot;'/>
   <p>
   <a href=quot;/Products/Detail/${product.ProductID}quot;>${product.ProductName}</a>
   <br />
   Price: ${String.Format(quot;{0:C2}quot;, product.UnitPrice)}
   <span class=quot;editlinkquot;>
   (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), quot;Editquot;)})
   </span>
   </p>
   <div style=quot;clear:both;quot;></div>
 </li>
</ul>            <li each=quot;var product in
                      ViewData.Modelquot;
            class=quot;${styles[productIndex%2]}quot;>
Testability
What is Testability?
What is Testability?


    The ability to test.
Testability Involves...

• A design approach
• Explicitly defining dependencies
• Isolating functionality
Testable?
private void linkAddClick(object sender, EventArgs e)
{

 string SQLInsert = quot;INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)quot;;


   using (SqlConnection connection = new SqlConnection(connectionString))

   {

   
 SqlCommand command = new SqlCommand(SQLInsert, connection);

   
 command.Parameters.AddWithValue(quot;@userquot;, txtUser.Text.Trim());

   
 command.Parameters.AddWithValue(quot;@passwordquot;, txtPassword.Text.Trim());

   
 connection.Open();

   
 command.CommandType = CommandType.Text;

   
 command.ExecuteNonQuery();

   
 connection.Close();

   }
}
Testable?
private void linkAddClick(object sender, EventArgs e)
{

 string SQLInsert = quot;INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)quot;;


   using (SqlConnection connection = new SqlConnection(connectionString))

   {

   
 SqlCommand command = new SqlCommand(SQLInsert, connection);

   
 command.Parameters.AddWithValue(quot;@userquot;, txtUser.Text.Trim());

   
 command.Parameters.AddWithValue(quot;@passwordquot;, txtPassword.Text.Trim());

   
 connection.Open();

   
 command.CommandType = CommandType.Text;

   
 command.ExecuteNonQuery();

   
 connection.Close();

   }
}
Testable?
public class UserController : Controller
{

 private IUserRepository _repository;

 public UserController(IUserRepository repository)

 {

 
 _repository = repository;

 }


   public ActionResult Show(string id)

   {

   
 User user = _repository.Load(id);

   
 return View(quot;Userquot;, user);

   }
}
Testable?
public class UserController : Controller
{

 private IUserRepository _repository;

 public UserController(IUserRepository repository)

 {

 
 _repository = repository;

 }


   public ActionResult Show(string id)

   {

   
 User user = _repository.Load(id);

   
 return View(quot;Userquot;, user);

   }
}
Let’s Test It
public class UserRepositoryStub : IUserRepository
{

 public User Load(string id)

 {

 
 return new User(id, quot;Aaronquot;, quot;Lerchquot;);

 }
}

[Test]
public void show_action_should_call_user_view()
{

 IUserRepository repository = new UserRepositoryStub();

 UserController controller = new UserController(repository);

 var result = controller.Show(quot;aaronlerchquot;);

 Assert.That(result, Is.Not.Null);

 Assert.That(result.ViewName, Is.EqualTo(quot;Userquot;);
}
AJAX
    “An AJAX-ified website is a
  requirement for being ‘Web 2.0’
     certified, making bajillions
of dollars, becoming hugely famous,
     regrowing your lost hair,
       and retiring to Tahiti.”
CODE!
Questions?

Comments?

Concerns?
Give MVC a Try!

   • Download ASP.NET MVC at
     http://www.codeplex.com/aspnet

   • TONS of resources linked from
     http://www.asp.net/mvc/

   • MVCContrib.com
   • CodeCampServer.com
Contact Me
   • aaronlerch@gmail.com
     http://www.aaronlerch.com/blog/

Más contenido relacionado

La actualidad más candente

Rest full
Rest fullRest full
Rest fullgfarid
 
So you think you know REST - DPC11
So you think you know REST - DPC11So you think you know REST - DPC11
So you think you know REST - DPC11Evert Pot
 
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...Microsoft Technet France
 
Microsoft Exchange 2013 deployment and coexistence
Microsoft Exchange 2013 deployment and coexistenceMicrosoft Exchange 2013 deployment and coexistence
Microsoft Exchange 2013 deployment and coexistenceMotty Ben Atia
 
Installing and Configuring Oracle Beehive Clients (whitepaper)
Installing and Configuring Oracle Beehive Clients (whitepaper)Installing and Configuring Oracle Beehive Clients (whitepaper)
Installing and Configuring Oracle Beehive Clients (whitepaper)Revelation Technologies
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web PerformanceEric ShangKuan
 
Migrating to Exchange 2010 and ad 2080 r2
Migrating to Exchange 2010 and ad 2080 r2Migrating to Exchange 2010 and ad 2080 r2
Migrating to Exchange 2010 and ad 2080 r2Nathan Winters
 
Browser APIs for data exchange: types and application
Browser APIs for data exchange: types and applicationBrowser APIs for data exchange: types and application
Browser APIs for data exchange: types and applicationPavel Klimiankou
 

La actualidad más candente (8)

Rest full
Rest fullRest full
Rest full
 
So you think you know REST - DPC11
So you think you know REST - DPC11So you think you know REST - DPC11
So you think you know REST - DPC11
 
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...
Exchange Server 2013 : upgrade migration et co-existence avec les anciennes v...
 
Microsoft Exchange 2013 deployment and coexistence
Microsoft Exchange 2013 deployment and coexistenceMicrosoft Exchange 2013 deployment and coexistence
Microsoft Exchange 2013 deployment and coexistence
 
Installing and Configuring Oracle Beehive Clients (whitepaper)
Installing and Configuring Oracle Beehive Clients (whitepaper)Installing and Configuring Oracle Beehive Clients (whitepaper)
Installing and Configuring Oracle Beehive Clients (whitepaper)
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
 
Migrating to Exchange 2010 and ad 2080 r2
Migrating to Exchange 2010 and ad 2080 r2Migrating to Exchange 2010 and ad 2080 r2
Migrating to Exchange 2010 and ad 2080 r2
 
Browser APIs for data exchange: types and application
Browser APIs for data exchange: types and applicationBrowser APIs for data exchange: types and application
Browser APIs for data exchange: types and application
 

Similar a Indy Tech Fest 2008 - ASP.NET MVC

ReST-ful Resource Management
ReST-ful Resource ManagementReST-ful Resource Management
ReST-ful Resource ManagementJoe Davis
 
Jeff conf milan 2017 Azure Functions
Jeff conf milan 2017  Azure FunctionsJeff conf milan 2017  Azure Functions
Jeff conf milan 2017 Azure FunctionsJessica Tibaldi
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0Cory Forsyth
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJSRiza Fahmi
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsPierre Spring
 
WebSockets - Today, in the Past, in Future and in Production.
WebSockets - Today, in the Past, in Future and in Production.WebSockets - Today, in the Past, in Future and in Production.
WebSockets - Today, in the Past, in Future and in Production.bodokaiser
 
REST in the shade of WCF
REST in the shade of WCFREST in the shade of WCF
REST in the shade of WCFSzymonPobiega
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumPierre Spring
 
Writing services in Ballerina_Ballerina Day CMB 2018
Writing services in Ballerina_Ballerina Day CMB 2018Writing services in Ballerina_Ballerina Day CMB 2018
Writing services in Ballerina_Ballerina Day CMB 2018Ballerina
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developersMario Cardinal
 
WebSockets On Fire
WebSockets On FireWebSockets On Fire
WebSockets On FireJef Claes
 
An introduction to HTTP/2 & Service Workers for SEOs
An introduction to HTTP/2 & Service Workers for SEOsAn introduction to HTTP/2 & Service Workers for SEOs
An introduction to HTTP/2 & Service Workers for SEOsTom Anthony
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...Distilled
 
REST and JAX-RS
REST and JAX-RSREST and JAX-RS
REST and JAX-RSGuy Nir
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administrationwebhostingguy
 

Similar a Indy Tech Fest 2008 - ASP.NET MVC (20)

ReST-ful Resource Management
ReST-ful Resource ManagementReST-ful Resource Management
ReST-ful Resource Management
 
Jeff conf milan 2017 Azure Functions
Jeff conf milan 2017  Azure FunctionsJeff conf milan 2017  Azure Functions
Jeff conf milan 2017 Azure Functions
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
 
Caching on the Edge
Caching on the EdgeCaching on the Edge
Caching on the Edge
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJS
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance Considerations
 
WebSockets - Today, in the Past, in Future and in Production.
WebSockets - Today, in the Past, in Future and in Production.WebSockets - Today, in the Past, in Future and in Production.
WebSockets - Today, in the Past, in Future and in Production.
 
REST in the shade of WCF
REST in the shade of WCFREST in the shade of WCF
REST in the shade of WCF
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler Forum
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
Starting With Php
Starting With PhpStarting With Php
Starting With Php
 
Writing services in Ballerina_Ballerina Day CMB 2018
Writing services in Ballerina_Ballerina Day CMB 2018Writing services in Ballerina_Ballerina Day CMB 2018
Writing services in Ballerina_Ballerina Day CMB 2018
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developers
 
Presentation (PPT)
Presentation (PPT)Presentation (PPT)
Presentation (PPT)
 
WebSockets On Fire
WebSockets On FireWebSockets On Fire
WebSockets On Fire
 
An introduction to HTTP/2 & Service Workers for SEOs
An introduction to HTTP/2 & Service Workers for SEOsAn introduction to HTTP/2 & Service Workers for SEOs
An introduction to HTTP/2 & Service Workers for SEOs
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
REST and JAX-RS
REST and JAX-RSREST and JAX-RS
REST and JAX-RS
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
 

Último

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Último (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

Indy Tech Fest 2008 - ASP.NET MVC

  • 1. Web Development with ASP.NET MVC Aaron Lerch Development Team Lead Interactive Intelligence
  • 2. • The MVC Pattern • MVC in ASP.NET • Testability • AJAX
  • 3. The MVC Pattern VIEW CONTROLLER MODEL
  • 4. The MVC Pattern VIEW CONTROLLER MODEL
  • 5.
  • 6. What is the Model? • Domain Objects • Data Transfer Objects • “Business Logic”
  • 7. What is the Model? • Domain Objects • Data Transfer Objects • “Business Logic” public class Person { } public class PersonDTO { } Repository<Person>.Load(personId) MessageService.Send(message)
  • 8.
  • 9. What is the View? • Format the Model • Render a display • Enable selecting of Actions
  • 10.
  • 11. What is the Controller? • Expose and Respond to Actions • Manipulate Model • Choose a View
  • 13.
  • 14. Acts like a 12 year old Is a 12 year old 20-something
  • 15. Acts like a 12 year old Is a 12 year old 20-something
  • 16. HTTP Client Server
  • 17. HTTP Client Server GET /foo.html HTTP 1.1
  • 18. HTTP Client Server GET /foo.html HTTP 1.1 200 OK Content-Type: application/xhtml+xml <html> <body>Foo</body> </html>
  • 19. HTTP Client Server
  • 20. HTTP Client Server GET /foo.html HTTP 1.1
  • 21. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html
  • 22. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html
  • 23. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html GET /bar.html HTTP 1.1
  • 24. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html GET /bar.html HTTP 1.1 200 OK <html> <body>Bar</body> </html>
  • 25. ASP.NET Client Server
  • 26. ASP.NET Client Server GET /foo.aspx HTTP 1.1
  • 27. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load Render
  • 28. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form>
  • 29. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form> POST /foo.aspx HTTP 1.1
  • 30. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form> POST /foo.aspx HTTP 1.1 Init Load LinkClicked Redirect Render
  • 31. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form> POST /foo.aspx HTTP 1.1 Init Load LinkClicked Redirect 302 Found Render Location: http://www.foobar.com/bar.aspx
  • 32. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form> POST /foo.aspx HTTP 1.1 Init Load LinkClicked Redirect 302 Found Render Location: http://www.foobar.com/bar.aspx GET /bar.aspx HTTP 1.1
  • 34. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1
  • 35. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”)
  • 36. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK
  • 37. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK
  • 38. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK GET /foos/ball HTTP 1.1
  • 39. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK GET /foos/ball HTTP 1.1 FoosController.Ball() View(“Ball”)
  • 40. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK GET /foos/ball HTTP 1.1 FoosController.Ball() View(“Ball”) 200 OK
  • 41. Request Flow Request URL Http Controller Response Routing Handler Route View Route View Handler Factory
  • 42. CODE!
  • 43. View Engines <table> <% foreach (ScheduleListing listing in schedule) { %> <tr> <td> <%=listing.StartTime %> - <%=listing.EndTime %><br /> <%= listing.Purpose %> </td> <% foreach (TrackListing track in tracks) { %> <td> <% SessionListing session = listing[track]; if (session != null) { %> <%= session.Title%><br /> (<%= session.Speaker.DisplayName%>) <% } else { %> <i>None</i> <% } %> </td> <% } %> </tr> <% } %> </table>
  • 44.
  • 45. NHaml #foo - foreach (var product in ViewData) - if (product.Category.CategoryName != null) %h2=product.Category.CategoryName - break %ul.productlist - foreach (var product in ViewData) %li = Html.Image(quot;/Content/Images/quot; + product.ProductID + quot;.jpgquot;, product.ProductName) .productdetail =Html.ActionLink(product.ProductName, quot;Detailquot;, new { ID=product.ProductID }) %br Price: =String.Format(quot;{0:C2}quot;, product.UnitPrice) %span.editlink ( =Html.ActionLink(quot;Editquot;, quot;Editquot;, new { ID=product.ProductID }) )
  • 46. NHaml #foo - foreach (var product in ViewData) - if (product.Category.CategoryName != null) %h2=product.Category.CategoryName - break %ul.productlist - foreach (var product in ViewData) %li = Html.Image(quot;/Content/Images/quot; + product.ProductID + quot;.jpgquot;, product.ProductName) .productdetail =Html.ActionLink(product.ProductName, quot;Detailquot;, new { ID=product.ProductID }) %br Price: “.productdetail” =String.Format(quot;{0:C2}quot;, product.UnitPrice) %span.editlink ( =Html.ActionLink(quot;Editquot;, quot;Editquot;, new { ID=product.ProductID }) ) becomes <div id=”productdetail”>
  • 47. Spark <ul class=quot;productlistquot;> <var styles='new[] {quot;oddquot;, quot;evenquot;}'/> <li each=quot;var product in ViewData.Modelquot; class=quot;${styles[productIndex%2]}quot;> <ProductImage style='quot;float:left;quot;'/> <p> <a href=quot;/Products/Detail/${product.ProductID}quot;>${product.ProductName}</a> <br /> Price: ${String.Format(quot;{0:C2}quot;, product.UnitPrice)} <span class=quot;editlinkquot;> (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), quot;Editquot;)}) </span> </p> <div style=quot;clear:both;quot;></div> </li> </ul>
  • 48. Spark <ul class=quot;productlistquot;> <var styles='new[] {quot;oddquot;, quot;evenquot;}'/> <li each=quot;var product in ViewData.Modelquot; class=quot;${styles[productIndex%2]}quot;> <ProductImage style='quot;float:left;quot;'/> <p> <a href=quot;/Products/Detail/${product.ProductID}quot;>${product.ProductName}</a> <br /> Price: ${String.Format(quot;{0:C2}quot;, product.UnitPrice)} <span class=quot;editlinkquot;> (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), quot;Editquot;)}) </span> </p> <div style=quot;clear:both;quot;></div> </li> </ul> <li each=quot;var product in ViewData.Modelquot; class=quot;${styles[productIndex%2]}quot;>
  • 51. What is Testability? The ability to test.
  • 52. Testability Involves... • A design approach • Explicitly defining dependencies • Isolating functionality
  • 53. Testable? private void linkAddClick(object sender, EventArgs e) { string SQLInsert = quot;INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)quot;; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(SQLInsert, connection); command.Parameters.AddWithValue(quot;@userquot;, txtUser.Text.Trim()); command.Parameters.AddWithValue(quot;@passwordquot;, txtPassword.Text.Trim()); connection.Open(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); connection.Close(); } }
  • 54. Testable? private void linkAddClick(object sender, EventArgs e) { string SQLInsert = quot;INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)quot;; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(SQLInsert, connection); command.Parameters.AddWithValue(quot;@userquot;, txtUser.Text.Trim()); command.Parameters.AddWithValue(quot;@passwordquot;, txtPassword.Text.Trim()); connection.Open(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); connection.Close(); } }
  • 55. Testable? public class UserController : Controller { private IUserRepository _repository; public UserController(IUserRepository repository) { _repository = repository; } public ActionResult Show(string id) { User user = _repository.Load(id); return View(quot;Userquot;, user); } }
  • 56. Testable? public class UserController : Controller { private IUserRepository _repository; public UserController(IUserRepository repository) { _repository = repository; } public ActionResult Show(string id) { User user = _repository.Load(id); return View(quot;Userquot;, user); } }
  • 57. Let’s Test It public class UserRepositoryStub : IUserRepository { public User Load(string id) { return new User(id, quot;Aaronquot;, quot;Lerchquot;); } } [Test] public void show_action_should_call_user_view() { IUserRepository repository = new UserRepositoryStub(); UserController controller = new UserController(repository); var result = controller.Show(quot;aaronlerchquot;); Assert.That(result, Is.Not.Null); Assert.That(result.ViewName, Is.EqualTo(quot;Userquot;); }
  • 58. AJAX “An AJAX-ified website is a requirement for being ‘Web 2.0’ certified, making bajillions of dollars, becoming hugely famous, regrowing your lost hair, and retiring to Tahiti.”
  • 59. CODE!
  • 61. Give MVC a Try! • Download ASP.NET MVC at http://www.codeplex.com/aspnet • TONS of resources linked from http://www.asp.net/mvc/ • MVCContrib.com • CodeCampServer.com Contact Me • aaronlerch@gmail.com http://www.aaronlerch.com/blog/