KEMBAR78
Deep Dive: MVC Controller Architecture | PPTX
MVC Controller ArchitectureDeep Dive
Holistic LookWhere do controllers fit?
Simple ApplicationA web siteAbstraction costs higher than returnDoes not integrate with business processesSolo project
Simple ApplicationController is the life of this app!
Simple ApplicationControllerViewModel
Layered ApplicationMore thought placed in designIntegrates into larger infrastructuresAbstraction necessary for reuseTeam project
Layered ApplicationController is the public interface
Layered ApplicationPresentation LayerCrosscutting ConcernsControllerViewViewModelBusiness LayerModelWorkflowComponentData Access LayerDAL ComponentGateway
Enterprise ApplicationComplexity determined by business needsBut strive for simplicityAnd reusabilityWill integrate into larger infrastructure
Enterprise ApplicationController is still the public interface
Enterprise ApplicationBUT
Enterprise ApplicationIt may be the life of an app if small…
Enterprise ApplicationThis is reduced…Web AppPublic ServiceConsole AppWPF AppWorkflow ServiceBusiness ServiceData ServiceDB
Enterprise ApplicationIt probably looks like this...
The ControllerDesigning the perfect cog
QuestionShould I use repositories?
Should I Use Repositories?Yes
Should I Use Repositories?Only composition logicEncapsulate and abstract other logic
ConsiderationsFlexibilityMaintainabilityRelated entitiesAre you using more than one repository per controller?
DEMOEncapsulation is simple
QuestionDo I need one repository per model?
One Repository Per Model?No
One Repository Per Model?Probably
Repository StyleCoarse-GrainedIEventRepositoryFine-GrainedIEventRepositoryIAttendeeRepository
QuestionHow do I transition to n-tier?
Transition to n-tier?Easier
Transition to n-tier?If you followed my previous recommendations
Breaking It UpPresentation LayerCrosscutting ConcernsControllerViewViewModelBusiness LayerModelWorkflowComponentData Access LayerDAL ComponentGateway
DEMOMoving to a tierWithout affecting your Controller!!!
The ControllerRoutingVerbsAction ResultsStandard ControllersCustom Controllers
RoutingHTTP Requestweb.configGlobal.asaxFavor Resources
RoutingPhysicalControllersLogical	Routes
DEMORouting
VerbsHTTP MethodsAcceptVerbs AttributeRESTful CRUDGETPUTPOSTDELETE
VerbsHEADOPTIONSCONNECTTRACECustom Verbs
DEMOVerbs
Action ResultsControllers do something when calledStandard action resultsViewResultJsonResultContentResultEmptyResultFileResultHttpUnauthorizedResult
Action ResultsMore Standard actionsJavaScriptResultRedirectResultRedirectToRouteResultMake your own!
DEMOCustom Action Results
Standard ControllersGreat for standard web applicationsConvention-basedEven non-standard controllers are convention based when used with views
Custom ControllersCan decorate the standard classCan inherit from ControllerBaseCan implement IControllerUse for non-standard applicationsor for more control
DEMOCustom Controllers
Controller as a ServiceMVC apps are typically web sitesThey can also be web servicesDo you have a mixed site/service?It can also be a pure service without JSON
DEMOController as a Service
ResourcesSoftware Application Developershttp://msdn.microsoft.com/Infrastructure Professionalshttp://technet.microsoft.com/technetindia msdnindia@technetindia@msdnindia
© 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.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.

Deep Dive: MVC Controller Architecture

Editor's Notes

  • #45 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.