O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency injection

Until now, we have seen how the object manager has control over the instantiation of dependencies. However, by convention, the object manager isn't supposed to be used directly in Magento. Rather, it should be used for system-level things that bootstrap Magento. We are encouraged to use the module's etc/di.xml file to instantiate objects.

Let's dissect one of the existing di.xml entries, such as the one found under the vendor/magento/module-admin-notification/etc/adminhtml/di.xml file for the Magento\Framework\Notification\MessageList type:

<type name="Magento\Framework\Notification\MessageList"> <arguments> <argument name="messages" xsi:type="array"> <item name="baseurl" xsi:type="string"> Magento\AdminNotification\Model\System ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required