When dependency injection containers get too big, and what can I do about it?

We all know why Injection Dependency is awesome because it makes the code less connected, easier to test, and much nicer to read! And then some decided to use the Injection Dependency Container , such as pimple for PHP, to help with the principle of dependency inversion in SOLID .

Therefore, creating your DiC, using a pimple, passing it to the controller and creating all your new objects in the closure, which in fact are created only when the developer calls $container['object'], is great!

But what happens when you have a very large set of classes in your application ? Say 1000+ and you want them to be available in the container?

It is clear that this will be a nightmare, putting all this in one file. What would be the best way to separate them, or would an alternative proposal be preferred?

On the separation side, how about:

  • Container creation
  • Including multiple files with classes grouped by application
  • Adding to the container in stages until the end of the file includes

On the other hand, I know Symfony2 uses XML / YAML to configure DiC, but it really doesn’t say much about the architectural side of things when an application contains so many classes.

What can a developer do if they have such a large code base?

+11
3

.

. , , . "DiC's", Symfony Pimple , . , , - Locator.

. $this->get('something') , , Symfony? . , API . !

, Injection of Dependency, Inversion of Control , , , .

, , , - . , . DI , , , ?

, () , , . (__construct()) , (Door Window), . ; . House , , . rdlowrey - auryn

, . Auryn - . , SOLID- . /? , alias , () . , - .

, " ", ! , , . , . . Laravel "".

+5

, DI.

: , , DI . , , , , , . , , ( , ). , DI, , . , , . , . , . ​​. , . . , . () .

Pimple - . DI-. , DI- , DI- , . , , Pimple DI. , , . . ? DI. , , . : , .

Pimple . : " ". DI ( ), DI- , ( , , ). . , ? Pimple , DI . , , .: -)

, Pimple DI. DI-. Pimple ( ), DI. , . , DI.

. ? DI? DI , . : , . , , . . , , - . : /, , - , ? DI-. DI . DI . DI, , , . DI , , , , , , , . , , DI-, .

+9

, , , . (, , ):

1000 ?

, , , . , , , . , . , , ..

, , Views , , DIC.

, , .

+7
source

Source: https://habr.com/ru/post/1649806/


All Articles