Application layer design: Is it more beneficial to have one action per class?

First, a quick disclaimer for all involved in this thread: My response assumes we’re talking about the traditional, web MVC.

With that out of the way, I think one vs many actions per class depends on whether you want your controllers to use a service locator or be a dependency injected service.

If you want your controllers to be a dependency injected service, then one action per class is the way to go. If you had multiple actions, then the controller’s constructor would have to accept dependencies that any of the actions might need. You could end up in a situation where one of the actions requires the database, which means the constructor would have to require it, but the action you actually invoke might not need it. One action per class means the action’s dependencies and the constructor’s arguments would match up.

But if your controllers were using service locator – which is enormously common in controllers; literally every framework I can think of, even those that allow for controllers to be dependency injected services, still use service locator most of the time for convenience – then the problem I described in the previous paragraph wouldn’t exist anymore. Each action would pull in its own dependencies without requiring anything from the constructor. In this scenario, you could have multiple actions per class without any problems.