0 votes
in Magneto by
What is Dependency Injection in Magneto?

1 Answer

0 votes
by
Dependency Injection is a technique in which, one object supplies dependencies of another object, and injection is the passing of dependency on the dependent object.

It is a software design pattern that allows a class to specify its dependencies without having to construct them.

The class delegates the responsibility of injecting the dependency to the calling class.

To define a dependency for a class, edit the di.xml file.

This permits loose coupling of code as object A doesn't require to be bothered with initializing its dependencies. Object B determines which implementations to offer to object A, based on a desired behavior or configuration.

Note: This is a critical concept to understand for extension developers because it forms the basis of how Magento composes its classes.
...