Dependency injection has become a de facto standard of modern-day software. Magento makes heavy use of this technique, based on mappings found in di.xml files. The workload of Magento's dependency injection is handled by the MagentoFrameworkObjectManagerObjectManager instance, which implements the lightweight MagentoFrameworkObjectManagerInterface.
The di.xml file configures the object manager, telling it how to handle the following:
- Argument injection
- Virtual types
- Proxies
- Factories
- Plugins
These features allow for a great degree of flexibility and extensibility, as we will soon see.
Every module can have a global and area-specific di.xml file.
Magento loads configuration files in the following order:
- Initial (app/etc/di.xml)
- Global (<ModuleDir>/etc/di.xml)
- Area-specific (<ModuleDir>/etc/<area>/di.xml)
When Magento reads all of these configuration files, it merges them all together by appending all nodes.