Indy Tech Fest 2008 - ASP.NET MVC

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Indy Tech Fest 2008 - ASP.NET MVC - Presentation Transcript

    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. What is the Model? • Domain Objects • Data Transfer Objects • “Business Logic”
    6. What is the Model? • Domain Objects • Data Transfer Objects • “Business Logic” public class Person { } public class PersonDTO { } Repository<Person>.Load(personId) MessageService.Send(message)
    7. What is the View? • Format the Model • Render a display • Enable selecting of Actions
    8. What is the Controller? • Expose and Respond to Actions • Manipulate Model • Choose a View
    9. MVC in ASP.NET
    10. Acts like a 12 year old Is a 12 year old 20-something
    11. Acts like a 12 year old Is a 12 year old 20-something
    12. HTTP Client Server
    13. HTTP Client Server GET /foo.html HTTP 1.1
    14. HTTP Client Server GET /foo.html HTTP 1.1 200 OK Content-Type: application/xhtml+xml <html> <body>Foo</body> </html>
    15. HTTP Client Server
    16. HTTP Client Server GET /foo.html HTTP 1.1
    17. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html
    18. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html
    19. HTTP Client Server GET /foo.html HTTP 1.1 302 Found Location: http://www.foobar.com/bar.html GET /bar.html HTTP 1.1
    20. 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>
    21. ASP.NET Client Server
    22. ASP.NET Client Server GET /foo.aspx HTTP 1.1
    23. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load Render
    24. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form>
    25. ASP.NET Client Server GET /foo.aspx HTTP 1.1 Init Load 200 OK Render <form>[VIEWSTATE]</form> POST /foo.aspx HTTP 1.1
    26. 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
    27. 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
    28. 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
    29. ASP.NET MVC Client Server
    30. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1
    31. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”)
    32. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK
    33. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK
    34. ASP.NET MVC Client Server GET /foo/bar HTTP 1.1 FooController.Bar() View(“Bar”) 200 OK GET /foos/ball HTTP 1.1
    35. 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”)
    36. 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
    37. Request Flow Request URL Http Controller Response Routing Handler Route View Route View Handler Factory
    38. CODE!
    39. 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>
    40. 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(\"/Content/Images/\" + product.ProductID + \".jpg\", product.ProductName) .productdetail =Html.ActionLink(product.ProductName, \"Detail\", new { ID=product.ProductID }) %br Price: =String.Format(\"{0:C2}\", product.UnitPrice) %span.editlink ( =Html.ActionLink(\"Edit\", \"Edit\", new { ID=product.ProductID }) )
    41. 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(\"/Content/Images/\" + product.ProductID + \".jpg\", product.ProductName) .productdetail =Html.ActionLink(product.ProductName, \"Detail\", new { ID=product.ProductID }) %br Price: “.productdetail” =String.Format(\"{0:C2}\", product.UnitPrice) %span.editlink ( =Html.ActionLink(\"Edit\", \"Edit\", new { ID=product.ProductID }) ) becomes <div id=”productdetail”>
    42. Spark <ul class=\"productlist\"> <var styles='new[] {\"odd\", \"even\"}'/> <li each=\"var product in ViewData.Model\" class=\"${styles[productIndex%2]}\"> <ProductImage style='\"float:left;\"'/> <p> <a href=\"/Products/Detail/${product.ProductID}\">${product.ProductName}</a> <br /> Price: ${String.Format(\"{0:C2}\", product.UnitPrice)} <span class=\"editlink\"> (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), \"Edit\")}) </span> </p> <div style=\"clear:both;\"></div> </li> </ul>
    43. Spark <ul class=\"productlist\"> <var styles='new[] {\"odd\", \"even\"}'/> <li each=\"var product in ViewData.Model\" class=\"${styles[productIndex%2]}\"> <ProductImage style='\"float:left;\"'/> <p> <a href=\"/Products/Detail/${product.ProductID}\">${product.ProductName}</a> <br /> Price: ${String.Format(\"{0:C2}\", product.UnitPrice)} <span class=\"editlink\"> (${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), \"Edit\")}) </span> </p> <div style=\"clear:both;\"></div> </li> </ul> <li each=\"var product in ViewData.Model\" class=\"${styles[productIndex%2]}\">
    44. Testability
    45. What is Testability?
    46. What is Testability? The ability to test.
    47. Testability Involves... • A design approach • Explicitly defining dependencies • Isolating functionality
    48. Testable? private void linkAddClick(object sender, EventArgs e) { string SQLInsert = \"INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)\"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(SQLInsert, connection); command.Parameters.AddWithValue(\"@user\", txtUser.Text.Trim()); command.Parameters.AddWithValue(\"@password\", txtPassword.Text.Trim()); connection.Open(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); connection.Close(); } }
    49. Testable? private void linkAddClick(object sender, EventArgs e) { string SQLInsert = \"INSERT INTO [Tabell] ([user], [password]) VALUES (@user, @password)\"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(SQLInsert, connection); command.Parameters.AddWithValue(\"@user\", txtUser.Text.Trim()); command.Parameters.AddWithValue(\"@password\", txtPassword.Text.Trim()); connection.Open(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); connection.Close(); } }
    50. 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(\"User\", user); } }
    51. 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(\"User\", user); } }
    52. Let’s Test It public class UserRepositoryStub : IUserRepository { public User Load(string id) { return new User(id, \"Aaron\", \"Lerch\"); } } [Test] public void show_action_should_call_user_view() { IUserRepository repository = new UserRepositoryStub(); UserController controller = new UserController(repository); var result = controller.Show(\"aaronlerch\"); Assert.That(result, Is.Not.Null); Assert.That(result.ViewName, Is.EqualTo(\"User\"); }
    53. 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.”
    54. CODE!
    55. Questions? Comments? Concerns?
    56. 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/

    + aaronlerchaaronlerch, 2 years ago

    custom

    2009 views, 2 favs, 1 embeds more stats

    The slides from my Indy Tech Fest presentation on A more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2009
      • 1916 on SlideShare
      • 93 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 0
    Most viewed embeds
    • 93 views on http://www.aaronlerch.com

    more

    All embeds
    • 93 views on http://www.aaronlerch.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories