Upload
chris-eargle
View
1.275
Download
1
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
MVC Controller Architecture
Deep Dive
Holistic Look
Where do controllers fit?
Simple Application
• A web site• Abstraction costs higher than return• Does not integrate with business
processes• Solo project
Simple Application
Controller is the life of this app!
Simple Application
ModelView
Controller
Layered Application
• More thought placed in design• Integrates into larger infrastructures• Abstraction necessary for reuse• Team project
Layered Application
Controller is the public interface
Layered Application
Workflow Component Model
Business Layer
DAL Component Gateway
Data Access Layer
ControllerViewViewModel
Presentation LayerCrosscutti
ng Concerns
Enterprise Application
• Complexity determined by business needs– But strive for simplicity• And reusability
• Will integrate into larger infrastructure
Enterprise Application
Controller is still the public interface
Enterprise Application
BUT
Enterprise Application
It may be the life of an app if small…
Enterprise Application
DB
Workflow ServiceData
Service
Business Service
WPF AppConsole
App Web App
This is reduced…
Public Service
Enterprise ApplicationIt probably looks like this...
The Controller
Designing the perfect cog
Question
Should I use repositories?
Should I Use Repositories?
Yes
Should I Use Repositories?
Only composition logic
Encapsulate and abstract other logic
Considerations
• Flexibility• Maintainability• Related entities• Are you using more than one
repository per controller?
DEMO
Encapsulation is simple
Question
Do I need one repository per model?
One Repository Per Model?
No
One Repository Per Model?
Probably
Repository Style
Coarse-Grained
Fine-Grained
IEventRepository
IEventRepository IAttendeeRepository
Question
How do I transition to n-tier?
Transition to n-tier?
Easier
Transition to n-tier?
If you followed my previous recommendations
Breaking It Up
Workflow Component Model
Business Layer
DAL Component Gateway
Data Access Layer
ControllerViewViewModel
Presentation LayerCrosscutti
ng Concerns
DEMO
Moving to a tierWithout affecting your Controller!!!
The Controller
• Routing• Verbs• Action Results• Standard Controllers• Custom Controllers
Routing
• HTTP Request• web.config• Global.asax• Favor Resources
Routing
Logical
Physical Controllers
Routes
DEMO
Routing
Verbs
• HTTP Methods• AcceptVerbs Attribute• RESTful CRUD– GET– PUT– POST– DELETE
Verbs
• HEAD• OPTIONS• CONNECT• TRACE• Custom Verbs
DEMO
Verbs
Action Results
• Controllers do something when called• Standard action results– ViewResult– JsonResult– ContentResult– EmptyResult– FileResult– HttpUnauthorizedResult
Action Results
• More Standard actions– JavaScriptResult– RedirectResult– RedirectToRouteResult
• Make your own!
DEMO
Custom Action Results
Standard Controllers
• Great for standard web applications• Convention-based– Even non-standard controllers are
convention based when used with views
Custom Controllers
• Can decorate the standard class• Can inherit from ControllerBase• Can implement IController• Use for non-standard applications– or for more control
DEMO
Custom Controllers
Controller as a Service
• MVC apps are typically web sites• They can also be web services• Do you have a mixed site/service?• It can also be a pure service without
JSON
DEMO
Controller as a Service
ResourcesSoftware Application
Developers
http://msdn.microsoft.com/
Infrastructure Professionals
http://technet.microsoft.com/
msdnindia technetindia @msdnindia @technetindia
© 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.