We have now service providers which do offer factories to create various objects, like forms, documents or applications. These factories are available through the container for now, but it is not recommended to use them that way as it turns it into a service locator.
Instead the factories should be injected. This missing piece needs to be solved. Atm, there is no proper way to inject dependencies into extensions, especially into the MVC stack. For example the Search View needs a router. The only way for now is to go through the container.
A solution can be that the search component does implement it's own MVCFactory which injects all the required dependencies. It does come with the cost that more classes will be introduced.
This is one of the things you can't fix in the MVC layer (and truthfully a fair bit of the API) without B/C breaks. The places in the API taking config arrays as constructor arguments aren't well suited for DI oriented code, those are places where you'd still need to direct instantiate the class and manually search for or build dependencies (you can't do
$container->get()
for a defined service or$container->buildObject()
to autowire something because you can't make that config array a container value).So you've really got a few options: