MVC: Actions on one controller vs multiple controllers

Webnoob

Member
Joined
Jul 6, 2016
Messages
16
Reaction score
0
Hi all, noob here... I am starting off with MVC. I see in the examples they use multiple actions on one controller. Each action returns a View. At what point do you actually use another controller, because it looks like you can do all the pages as actions on one controller?
 
The controllers are to keep things organised. For instance you can have a FileController (/File) and then do all your file related stuff in there.

As the site grows you don't want everything in the Home controller because it will become a pain to manage.

It's also nice to see the URL showing you which section you are in on the webpage.
 
The controllers are to keep things organised. For instance you can have a FileController (/File) and then do all your file related stuff in there.

As the site grows you don't want everything in the Home controller because it will become a pain to manage.

It's also nice to see the URL showing you which section you are in on the webpage.

Ah ok tx for the quick reply
 
We like doing a controller per business object. So if you have a customer object, you have a customer controller that deals with presenting all views and actions pertaining to it ( list, edit, delete, details etc )
 
The single do it all controller is nicknamed the god controller, because it's just a variation of the god object anti-pattern.

Fat controllers are considered God controllers when they take responsibility for handling too many requests. The pinnacle case is a site that has just the one controller handling all requests.
 
[)roi(];17928635 said:
The single do it all controller is nicknamed the god controller, because it's just a variation of the god object anti-pattern.

Fat controllers are considered God controllers when they take responsibility for handling too many requests. The pinnacle case is a site that has just the one controller handling all requests.

Agreed SRP springs to mind..

We like doing a controller per business object. So if you have a customer object, you have a customer controller that deals with presenting all views and actions pertaining to it ( list, edit, delete, details etc )
That makes sense
 
It helps keep things modular.

So you can work on only a specific portion of the app and if it breaks (which does happen even after testing extensively), it only effects that one piece making it quick and easy to locate and fix.
 
Top
Sign up to the MyBroadband newsletter
X