I have a class I call my Dispatcher
and when its dispatch()
method is run it instantiates the requested controller.
My AbstractController
has a constructor like
public function __construct(RequestInterface $request, ResponseInterface $response, ViewFactory $viewFactory, ServiceFactory $serviceFactory)
As you can see my controllers have 4 dependencies.
At the moment when I instantiate my Dispatcher
I inject the ViewFactory
and ServiceFactory
into its constructor and then when I run the dispatch()
method I supply the Request
and Response
objects as arguments and I can then inject all four dependencies into my controller.
Would it be better to just supply all the controllers dependencies when calling the dispatch()
method or supply them all in the constructor of the Dispatcher
and then run a dispatch()
method with no arguments or is there a better way overall?