The principle of DIP of the SOLID and of Autowiring DI container?

The DIP principle States: the dependencies should be on abstractions, not concrete implementations.

For example such code:
public function __construct(LoggerInterface $logger) { }

The dependence on the interface.

If you are using DI containers with autowiring to work. To work autowiring need to assigned a specific class according to.

Please explain what I misunderstood? Or why you see a contradiction in principle DIP and tools to ease the work with dependencies?
April 7th 20 at 10:43
3 answers
April 7th 20 at 10:45
Solution
Dependency injection is when we pass A class A class B via the constructor or setter that he worked with him, and did not create it in their sutrah.
Dependency Inversion is when we are in class A are not specific to the implementation and interfaces: the interfaces in the constructor, methods, return types, etc.
These are two different concepts, which sometimes combine into one, and sometimes confused.
Now, autowiring is about Dependency injection, and D in solid is about Dependency Inversion. One does not interfere and does not violate.
Clear and understandable, thank you! - Conor commented on April 7th 20 at 10:48
April 7th 20 at 10:47
Why not? Maybe you don't use or don't know how to use it?

In the DI container we "bind" a class that implements the interface. So wherever there is this interface going to work is created and "bound" us class.

There seems to be quite simple and clear.
Thank you, can I please have an example? In any implementation of DI container will do. - Conor commented on April 7th 20 at 10:50
@7876010, for example Symfony For example, Yii2 - antonia_Borer commented on April 7th 20 at 10:53
php-di.org/doc/autowiring.html#limitations

It says that it will not work autowiring if there is no argument type, or the type is not a concrete class, and interface for example. - Conor commented on April 7th 20 at 10:56
@7876010, in your example public function log(LoggerInterface $logger) { }
Type is LoggerInterface - antonia_Borer commented on April 7th 20 at 10:59
@antonia_Borer, LoggerInterface interface. Where autowiring will know which class to initialize ? - Conor commented on April 7th 20 at 11:02
@7876010, it turns out that you need to explicitly in the container you specify. Then the meaning autowiring?
But if you want autowiring't something impossible depending on the interface you specify. Or I do have it all wrong. - Conor commented on April 7th 20 at 11:05
@7876010, you don't describe better than in the documentation. Threw you the above links to the Symphony and yii2. There can understand.

you especially don't need to know how it all works inside. Now, try to understand what you need to do in order for this to work as it should. And if you want to deepen you study.

You don't know where the computer builds all the process. You just poke at the keys and facilitate certain actions. So it is here. You just put the dependencies in the DI, and how he defines them is not particularly important now for you. - antonia_Borer commented on April 7th 20 at 11:08
@7876010, you just need to read and not ask a bunch of questions) You are on the right track. Just a little thoughtfulness, calmness and attentiveness) - antonia_Borer commented on April 7th 20 at 11:11
@7876010,
it turns out that you need to explicitly in the container you specify.

Yes.

Then the meaning autowiring?

Takes care of sensitive work, when you can determine what to injecting. Well, Yes - in Symfony you can set the default implementation of the interface.

DIP and not about autowiring. - bernice commented on April 7th 20 at 11:14
April 7th 20 at 10:49
You have 2 options:
1. Trying to fix someone else's mistakes.
2. Think with your head.

I chose the 2nd.
I do not understand.. - Conor commented on April 7th 20 at 10:52
@7876010read carefully (slowly!) your question and make a comparison by paragraphs of my answer. - joaquin11 commented on April 7th 20 at 10:55
@joaquin11still don't understand) talking in riddles - Conor commented on April 7th 20 at 10:58
@7876010You have written is true:
If you are using DI containers with autowiring to work. To work autowiring need to assigned a specific class according to.
But at the same time trying to deny it, drawing others into it.
Why? - joaquin11 commented on April 7th 20 at 11:01

Find more questions by tags PHPOOPSOLID