Junior — Middle
Can dependency injection be considered a form of inversion of control?
sobes.tech AI
Answer from AI
Yes, dependency injection (DI) can be considered one of the manifestations of inversion of control (IoC).
Inversion of control is a principle where the creation and binding of objects are delegated to an external container or framework, rather than being implemented directly in the code. Dependency injection implements this principle by providing objects with their dependencies from outside, instead of objects creating or searching for them themselves.
Example: instead of a class creating an instance of a dependency itself, it receives it through a constructor or setter, and an external container is responsible for creating and passing the necessary objects.