Magento 2 is built around the Dependency Injection principle. It is a lot more than retrieving classes through the constructor which already leads to better code quality. Do you know all the ways how you can modify the class hierachy in Magento 2? How do they work, in which cases are they beneficial?
Fully understanding how Dependency Injection and the Object Manager work is key to advanced Magento 2 backend development. The talk will start with a broad overview of Dependency Injection in general and in Magento 2. Afterwards, Andreas will explain the details and show easy-to-understand examples, based on real-life projects and on his experience as a Magento 2 trainer.
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dependency Injection Extended: the way to advanced Magento 2 development
1. #MM18PL
Dependency Injection Extended
The Way to advanced Magento 2 Development
September 10th 2018 – Meet Magento PL
Andreas von Studnitz – integer_net – @avstudnitz
10. #MM18PL#MM18PL
Instantiate a new class (1)
Does an object of that type
already exist?
Reuse existing object Create new object
Yes No
Get type from constructor parameter
16. #MM18PL#MM18PL
Instantiate a new class (2)
Get type from constructor parameter
Does an object of that type
already exist?
Reuse existing object Create new object
Yes No
Does a preference exist?
Yes NoUse preference
as type
40. #MM18PL
“
#MM18PL
“Debugging is twice as hard as
writing the code in the first place.
Therefore, if you write the code as
cleverly as possible, you are, by
definition, not smart enough to
debug it.”
- Brian Kernighan