T
T
topuserman2020-02-08 22:10:56
PHP
topuserman, 2020-02-08 22:10:56

DIP principle from SOLID and Autowiring from DI containers?

The DIP principle states that dependencies should be on abstractions, not on a specific implementation.

For example this code:

public function __construct(LoggerInterface $logger) { }

Interface dependency.

When using DI containers with autowiring - will not work. For autowiring to work, you need to specify a specific class in the dependency.

Please explain what I misunderstood? Or why do I see a contradiction between the DIP principle and the tool for simplifying work with dependencies?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergei Iamskoi, 2020-02-10
@topuserman

Dependency injection is when we pass class B to class A through a constructor or setter so that it works with it, and does not create it in its own interiors.
Dependency Inversion is when we work in class A not with a specific implementation, but with interfaces: we specify interfaces in the constructor, in methods, in return types, etc.
These are two different concepts, which are sometimes combined into one, and sometimes they are confused.
So, autowiring is about Dependency injection, and D in solid is about Dependency Inversion. One does not interfere with the other and does not violate.

X
xmoonlight, 2020-02-09
@xmoonlight

You have 2 options:
1. Trying to fix someone's mistakes.
2. Think with your head.
I chose - 2nd.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question