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 \Message\Baseurl</item> <item name="security" xsi:type="string"> Magento\AdminNotification...