SlideShare uma empresa 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/

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante 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
 

Semelhante 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

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Último (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

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/