Looking at the core Magento2 modules in the vendor folder, I notice that there are di.xml placed in different folders etc/adminhtml/di.xml, etc/frontend/di.xml and etc/di.xml.

The Magento_Cms module itself has di.xml in all 3 different folders!

What's the effect of placing the di.xml in the 3 different folders? How can I know when I should place my di.xml in which folder?

2 Answers 2


Each module can have a global and area-specific di.xml file. Magento reads all the di.xml configuration files declared in the system and merges them all together by appending all nodes.

As a general rule, the area specific di.xml files should configure dependencies for the presentation layer, and your module’s global di.xml file should configure the remaining dependencies.

Magento loads The configuration in the following stages:

  1. Initial (app/etc/di.xml)
  2. Global (<moduleDir>/etc/di.xml)
  3. Area-specific (<moduleDir>/etc/<area>/di.xml)

During bootstrapping, each application entry point loads the appropriate di.xml files for the requested area.


  • Also, plugins in area-specific di.xml are not always generated in developer mode.
    – David Tay
    Oct 8, 2020 at 15:35

'di.xml' is used for set dependency.

You can place it in etc folder or frontend or adminhtml folder

but purpose to set it in different folder is :

  1. frontend : all dependency which apply for frontend is needed to set in it, so developer can have clear idea about dependency applied for frontend development.
  2. adminhtml : all dependency applied to admin should be placed at adminthml, so developer can identify it easily.
  3. etc : Its for general dependency, so we can define dependency which can be used in both frontend as well as backend.

Different folder created for different dependency can make it easy to find any dependency applied on Backend or frontend or both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.