Deep Dive: MVC Controller Architecture

1,704 views

Published on

The driving force behind the MVC architecture is the controller. It returns the appropriate view and model for a request, but that is not the end of the story. In ASP.NET MVC, the controller is much more powerful. I will go deep into the infrastructure of the controller. You will discover that there is much more to this powerful framework than is shown in typical examples, and you will be able to use this knowledge for business scenarios that go beyond serving simple web pages.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,704
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
31
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • The title of this demo is actually funny to me. Controllers are already services. A request comes in, it is routed to the appropriate action on a controller, and a response is sent back out. Controllers are services that typically respond with information to be rendered in a browser.
  • Deep Dive: MVC Controller Architecture

    1. 1. MVC Controller Architecture<br />Deep Dive<br />
    2. 2. Holistic Look<br />Where do controllers fit?<br />
    3. 3. Simple Application<br />A web site<br />Abstraction costs higher than return<br />Does not integrate with business processes<br />Solo project<br />
    4. 4. Simple Application<br />Controller is the life of this app!<br />
    5. 5. Simple Application<br />Controller<br />View<br />Model<br />
    6. 6. Layered Application<br />More thought placed in design<br />Integrates into larger infrastructures<br />Abstraction necessary for reuse<br />Team project<br />
    7. 7. Layered Application<br />Controller is the public interface<br />
    8. 8. Layered Application<br />Presentation Layer<br />Crosscutting Concerns<br />Controller<br />View<br />ViewModel<br />Business Layer<br />Model<br />Workflow<br />Component<br />Data Access Layer<br />DAL Component<br />Gateway<br />
    9. 9. Enterprise Application<br />Complexity determined by business needs<br />But strive for simplicity<br />And reusability<br />Will integrate into larger infrastructure<br />
    10. 10. Enterprise Application<br />Controller is still the public interface<br />
    11. 11. Enterprise Application<br />BUT<br />
    12. 12. Enterprise Application<br />It may be the life of an app if small…<br />
    13. 13. Enterprise Application<br />This is reduced…<br />Web App<br />Public Service<br />Console App<br />WPF App<br />Workflow Service<br />Business Service<br />Data Service<br />DB<br />
    14. 14. Enterprise Application<br />It probably looks like this...<br />
    15. 15. The Controller<br />Designing the perfect cog<br />
    16. 16. Question<br />Should I use repositories?<br />
    17. 17. Should I Use Repositories?<br />Yes<br />
    18. 18. Should I Use Repositories?<br />Only composition logic<br />Encapsulate and abstract other logic<br />
    19. 19. Considerations<br />Flexibility<br />Maintainability<br />Related entities<br />Are you using more than one repository per controller?<br />
    20. 20. DEMO<br />Encapsulation is simple<br />
    21. 21. Question<br />Do I need one repository per model?<br />
    22. 22. One Repository Per Model?<br />No<br />
    23. 23. One Repository Per Model?<br />Probably<br />
    24. 24. Repository Style<br />Coarse-Grained<br />IEventRepository<br />Fine-Grained<br />IEventRepository<br />IAttendeeRepository<br />
    25. 25. Question<br />How do I transition to n-tier?<br />
    26. 26. Transition to n-tier?<br />Easier<br />
    27. 27. Transition to n-tier?<br />If you followed my previous recommendations<br />
    28. 28. Breaking It Up<br />Presentation Layer<br />Crosscutting Concerns<br />Controller<br />View<br />ViewModel<br />Business Layer<br />Model<br />Workflow<br />Component<br />Data Access Layer<br />DAL Component<br />Gateway<br />
    29. 29. DEMO<br />Moving to a tier<br />Without affecting your Controller!!!<br />
    30. 30. The Controller<br />Routing<br />Verbs<br />Action Results<br />Standard Controllers<br />Custom Controllers<br />
    31. 31. Routing<br />HTTP Request<br />web.config<br />Global.asax<br />Favor Resources<br />
    32. 32. Routing<br />Physical<br />Controllers<br />Logical <br />Routes<br />
    33. 33. DEMO<br />Routing<br />
    34. 34. Verbs<br />HTTP Methods<br />AcceptVerbs Attribute<br />RESTful CRUD<br />GET<br />PUT<br />POST<br />DELETE<br />
    35. 35. Verbs<br />HEAD<br />OPTIONS<br />CONNECT<br />TRACE<br />Custom Verbs<br />
    36. 36. DEMO<br />Verbs<br />
    37. 37. Action Results<br />Controllers do something when called<br />Standard action results<br />ViewResult<br />JsonResult<br />ContentResult<br />EmptyResult<br />FileResult<br />HttpUnauthorizedResult<br />
    38. 38. Action Results<br />More Standard actions<br />JavaScriptResult<br />RedirectResult<br />RedirectToRouteResult<br />Make your own!<br />
    39. 39. DEMO<br />Custom Action Results<br />
    40. 40. Standard Controllers<br />Great for standard web applications<br />Convention-based<br />Even non-standard controllers are convention based when used with views<br />
    41. 41. Custom Controllers<br />Can decorate the standard class<br />Can inherit from ControllerBase<br />Can implement IController<br />Use for non-standard applications<br />or for more control<br />
    42. 42. DEMO<br />Custom Controllers<br />
    43. 43. Controller as a Service<br />MVC apps are typically web sites<br />They can also be web services<br />Do you have a mixed site/service?<br />It can also be a pure service without JSON<br />
    44. 44. DEMO<br />Controller as a Service<br />
    45. 45. Resources<br />Software Application Developers<br />http://msdn.microsoft.com/<br />Infrastructure Professionals<br />http://technet.microsoft.com/<br />technetindia<br /> msdnindia<br />@technetindia<br />@msdnindia<br />
    46. 46. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />

    ×