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
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>
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
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
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.”
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/