? J4 Issue ?
avatar laoneo
laoneo
15 Oct 2018

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.

avatar laoneo laoneo - open - 15 Oct 2018
avatar joomla-cms-bot joomla-cms-bot - change - 15 Oct 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Oct 2018
avatar mbabker mbabker - change - 15 Oct 2018
The description was changed
avatar mbabker mbabker - edited - 15 Oct 2018
avatar brianteeman brianteeman - change - 16 Oct 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 16 Oct 2018
avatar mbabker
mbabker - comment - 17 Oct 2018

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:

  • Accept the classes can't be DI'd and use the container as a service locator
    • Generally accepted as a bad practice, but gets the job done
  • Require some kind of middle layer factory that creates the classes and uses setter injection to push dependencies after the class is instantiated
    • Complicates the API, objects get created in invalid state
  • Formulate a plan to break the hard reliance on the config arrays, deprecate existing constructor signatures, and move classes to DI oriented approaches
    • Long term B/C implications, probably has implications on how some classes are configured, but similarly gives us a chance to re-evaluate the base MVC class designs and determine what bits and pieces belong in a config array and what could/should be done through more explicit configuration as setter methods or explicit constructor dependencies
avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status New Discussion
avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Mar 2019
Category Code style
avatar franz-wohlkoenig franz-wohlkoenig - change - 7 Apr 2019
Labels Added: ?
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 7 Apr 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 9 Apr 2019
Category Code style
avatar laoneo laoneo - change - 22 Dec 2020
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2020-12-22 18:28:26
Closed_By laoneo
avatar laoneo laoneo - close - 22 Dec 2020

Add a Comment

Login with GitHub to post a comment