DEV Community

Cover image for How Many types of Dependency Injection in Magento 2
webgurudev
webgurudev

Posted on

How Many types of Dependency Injection in Magento 2

What are the different types of Dependency Injection in Magento 2 and how is it utilized? Automatic Dependency Injection (ADI) in Magento 2 eradicates the requirement for an object to manually seek out its dependent objects. ADI encompasses three distinct types: Constructor Injection, Setter Injection, and Interface Injection. In Magento 2, ADI, specifically Constructor Injection, is employed, where dependencies are passed as parameters in the constructor to comply with injection guidelines.

This approach serves as an alternative to the Mage Class method employed in Magento 1. To illustrate this concept, an example within Magento 2 is provided.

For more information , please visit this :- https://webguru.dev/how-many-types-of-dependency-injection-in-magento-2/

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more