Build extension¶
Di.xml file¶
Areas and application entry points¶
-
Magento loads the configuration in the following stages:
- Initial (app/etc/di.xml)
- Global (
/etc/di.xml) - Area-specific (
/etc//di.xml)
Abstraction-implementation mappings¶
<!-- File: app/etc/di.xml -->
<config>
<preference for="Magento\Core\Model\UrlInterface" type="Magento\Core\Model\Url" />
</config>
Magento\Framework\ObjectManager\ObjectManager.php
Magento\Framework\ObjectManager\Config.php
di.xml, save info about Preference in all file di.xml to ObjectManager\Config::_preferences and ObjectManager\Config::_cache.
When call \Magento\Framework\ObjectManagerInterface::create($type), Magento call
public function create($type, array $arguments = [])
{
return $this->_factory->create($this->_config->getPreference($type), $arguments);
}
Config get preference for once type, then init and return object with construct of preference.