3

This is an architecture level question. At my work place the controllers are tied to having just one application service to call the application level code. However from my learning of the onion architecture and asp.net mvc, it seems probable to me that an asp.net mvc controller might need to call several application services from the application services layer of the app and hence would have dependencies on many application services (not just one). Am I right in thinking this?

Second Part:

How are controllers usually designed? I am not a big fan of a monolithic controller and I know that a view could potentially be making calls to multiple controllers. To me a controller is just a way to logically group the actions which are the core part where the request processing takes place.

Having said this, what would the asp.net mvc experts and onion architecture experts suggest. Do we have a controller per view (leads to monolothic controller) or do we have a controller per application service.

OR

as I feel it should be :

  1. controllers are designed only to be logical groupings of actions. This would mean a view could be calling multiple controllers and a controller can be called by multiple views.

  2. Controller can be leveraging multiple application services. Although many a times I have seen that the action methods correspond largely with the method that is called in the application services layer. But this should not be a motivation to design one controller per application service.

Looking for some good ideas or opinions. Thank you!

  • Having strictly one service that the controller uses is more of a facade pattern to me. It can be useful in some scenarios but is not a strict requirement. More often you will indeed have multiple services. Being restricted to one will likely lead to blatant violations of the single responsibility principle. I agree with your numbered points. The front end should be free to break up any workflows however it sees fit. – stephen.vakil Oct 06 '16 at 21:16
  • "Having strictly one service that the controller uses is more of a facade pattern to me" - do you mean this single service is typically designed to be a facade over the multiple services that the controller could be accessing. In this case would'nt it make sense for the controller to declare those dependencies explicity rather than throwing in the facade and abstracting the dependency away. – Soham Joshi Oct 06 '16 at 23:01

0 Answers0