It’s almost exactly the same as with the command example, the only difference being that you have to make sure that you include and pass on the arguments required for the parent class constructor, which in the case of a controller would probably be the server request:
class SomeController extends Controller
{
public function __construct(\Some\Dependency $dep, \Cake\Http\ServerRequest $request)
{
parent::__construct($request);
// ...
}
// ...
}
Then add the dependencies and the controller to the container, and that should be it:
IMO its annoying to have to require all this. I love CakePHP, but in other frameworks you can just slap dependencies into constructors and let auto-wiring handle everything else. I would be nice if CakePHP could more close integrate with The Leagues auto-wiring functionality or add a #[CakeService] attribute to classes you want to be injected automatically that wires this up for you.
The docs have been updated to show how to avoid the cyclic dependency issue pointed out by @cnizzardini above. We have even changed the signature of Controller::__construct() in 5.x to avoid this cyclic dependency.