MVC Controller Architecture Deep Dive Holistic Look Where

  • Slides: 46
Download presentation
MVC Controller Architecture Deep Dive

MVC Controller Architecture Deep Dive

Holistic Look Where do controllers fit?

Holistic Look Where do controllers fit?

Simple Application • A web site • Abstraction costs higher than return • Does

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 Controller is the life of this app!

Simple Application Controller View Model

Simple Application Controller View Model

Layered Application • • More thought placed in design Integrates into larger infrastructures Abstraction

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 Controller is the public interface

Layered Application Presentation Layer View Controller Business Layer Workflow Component Model Data Access Layer

Layered Application Presentation Layer View Controller Business Layer Workflow Component Model Data Access Layer DAL Component Gateway Crosscutting Concerns View. Model

Enterprise Application • Complexity determined by business needs – But strive for simplicity •

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 Controller is still the public interface

Enterprise Application BUT

Enterprise Application BUT

Enterprise Application It may be the life of an app if small…

Enterprise Application It may be the life of an app if small…

Enterprise Application This is reduced… WPF App Business Service Public Service Console App Data

Enterprise Application This is reduced… WPF App Business Service Public Service Console App Data Service DB Web App Workflow Service

Enterprise Application It probably looks like this. . .

Enterprise Application It probably looks like this. . .

The Controller Designing the perfect cog

The Controller Designing the perfect cog

Question Should I use repositories?

Question Should I use repositories?

Should I Use Repositories? Yes

Should I Use Repositories? Yes

Should I Use Repositories? Only composition logic Encapsulate and abstract other logic

Should I Use Repositories? Only composition logic Encapsulate and abstract other logic

DEMO Encapsulation is simple

DEMO Encapsulation is simple

Question Do I need one repository per model?

Question Do I need one repository per model?

One Repository Per Model? No

One Repository Per Model? No

One Repository Per Model? Probably

One Repository Per Model? Probably

Repository Style Coarse-Grained IEvent. Repository Fine-Grained IEvent. Repository IAttendee. Repository

Repository Style Coarse-Grained IEvent. Repository Fine-Grained IEvent. Repository IAttendee. Repository

Question How do I transition to n-tier?

Question How do I transition to n-tier?

Transition to n-tier? Easier

Transition to n-tier? Easier

Transition to n-tier? If you followed my previous recommendations

Transition to n-tier? If you followed my previous recommendations

Breaking It Up Presentation Layer View Controller Business Layer Workflow Component Model Data Access

Breaking It Up Presentation Layer View Controller Business Layer Workflow Component Model Data Access Layer DAL Component Gateway Crosscutting Concerns View. Model

DEMO Moving to a tier Without affecting your Controller!!!

DEMO Moving to a tier Without affecting your Controller!!!

Considerations • • Flexibility Maintainability Related entities Are you using more than one repository

Considerations • • Flexibility Maintainability Related entities Are you using more than one repository per controller?

The Controller • • • Routing Verbs Action Results Standard Controllers Custom Controllers

The Controller • • • Routing Verbs Action Results Standard Controllers Custom Controllers

Routing • • HTTP Request web. config Global. asax Favor Resources

Routing • • HTTP Request web. config Global. asax Favor Resources

Routing Physical Controllers Logical Routes

Routing Physical Controllers Logical Routes

DEMO Routing

DEMO Routing

Verbs • HTTP Methods • Accept. Verbs Attribute • RESTful CRUD – GET –

Verbs • HTTP Methods • Accept. Verbs Attribute • RESTful CRUD – GET – PUT – POST – DELETE

Verbs • • • HEAD OPTIONS CONNECT TRACE Custom Verbs

Verbs • • • HEAD OPTIONS CONNECT TRACE Custom Verbs

DEMO Verbs

DEMO Verbs

Action Results • Controllers do something when called • Standard action results – View.

Action Results • Controllers do something when called • Standard action results – View. Result – Json. Result – Content. Result – Empty. Result – File. Result – Http. Unauthorized. Result

Action Results • More Standard actions – Java. Script. Result – Redirect. To. Route.

Action Results • More Standard actions – Java. Script. Result – Redirect. To. Route. Result • Make your own!

DEMO Custom Action Results

DEMO Custom Action Results

Standard Controllers • Great for standard web applications • Convention-based – Even non-standard controllers

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 Controller. Base

Custom Controllers • • Can decorate the standard class Can inherit from Controller. Base Can implement IController Use for non-standard applications – or for more control

DEMO Custom Controllers

DEMO Custom Controllers

Controller as a Service • • MVC apps are typically web sites They can

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

DEMO Controller as a Service

Resources Software Application Developers Infrastructure Professionals http: //msdn. microsoft. com/ http: //technet. microsoft. com/

Resources Software Application Developers Infrastructure Professionals http: //msdn. microsoft. com/ http: //technet. microsoft. com/ msdnindia @msdnindia technetindia @technetindia

© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names

© 2011 Microsoft Corporation. All rights reserved. Microsoft, 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.