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

More Related Content

What's hot

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
 

What's hot (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 to 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 to 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
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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/