3

The default DI configuration of Magento 2 is placed in app/etc/di.xml alongside other configuration files like env.php and config.php. While the latter are files that you are meant to modify, the di.xml should not be modified at all. If this is so, why is this file not placed in a folder like vendor (for instance vendor/magento2-base/etc/di.xml)? For newbies, this might be confusing as they don't know which files they are allowed to modify and which not.

1
  • Not sure exactly but my guess because magento consider that as a global file which gets used for both vendor and app/code. Like global preferences. Commented Apr 14, 2017 at 7:28

1 Answer 1

0

I don't know the answer, but I can speculate and try to find some arguments for it.
It's not vendor because vendor is reserved for packages. And di.xml is not part of a package.
Making a package as you suggest vendor/magento2-base/etc/di.xml would introduce unwanted dependencies.
The global di.xml is there just to provide composition for your application so it should be part of your application.
I have a strong feeling that is also used by the installer, and not only the application.
So having it a module means that theoretically it can be disabled and you don't want that.

Look at it as a global configuration file for your application.

2
  • Thanks Marius. To further comment, actually app/etc/di.xml originates from vendor/magento2-base/app/etc/di.xml because the magento2-base is not much more than a package to kickstart the Magento filesystem. But because magento2-base is the base of every M2 project, it does make sense to reuse its app/etc/di.xml. However, its a copy and copying files is always ugly :) I like your comment on that a module could be disabled and therefore the global DI configuration should not be in a module. However, magento2-base and framework are not modules, only composer packages. Commented Apr 14, 2017 at 9:49
  • Hello @marius, How app/etc/di.xml file is initialized and when?Please let me know in detail.
    – akgola
    Commented Mar 1, 2019 at 12:14

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.