4

As far as I know you can set a preference for an Interface in the di.xml of an extension. But i see several Interfaces without any reference in the di.xml. How are these instantiated?

Examples: app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

The constructor contains that code:

 \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,

or app/code/Magento/Payment/Model/Info.php

\Magento\Framework\Encryption\EncryptorInterface $encryptor
3

the preference for \Magento\Framework\Encryption\EncryptorInterface is set int app/etc/di.xml. That file is not module dependent but it is merged with the other di.xml files.
The $connection parameter defaults to null. This means that if it's not specified, the DI container will not try to instantiate the preference for \Magento\Framework\DB\Adapter\AdapterInterface. Instead it will just use null for this.

  • Thanks Marius i was missing the app/etc/di.xml My issue is that i am getting a fatal error in my collection class, using the AdapterInterface in my constructor Fatal error: Cannot instantiate interface Magento\Framework\DB\Adapter\AdapterInterface Any idea? – Sakis Feb 25 '16 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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