D
D
Dmitry2018-12-27 12:08:24
Magento
Dmitry, 2018-12-27 12:08:24

Why is Magento 2 trying to instantiate an interface instead of correctly getting a class from a DI config?

Context:
- vendor package with the described factory interface (conditionally SomeServiceFactoryInterface );
- a module in Magento, in the DI configuration (MyModule/etc/di.xml) of which the factory interface bind to its implementation is explicitly registered (

<preference for="Vendor\SomeService\Factory\SomeServiceFactoryInterface" type="MyCompany\MyModule\Service\Factory\SomeServiceFactory" />
);
When trying to execute any Magento CLI command (even just bin/magento ) it immediately crashes with the following message:
error log

PHP Fatal error: Uncaught Error: Cannot instantiate interface Vendor\SomeService\Factory\SomeServiceFactoryInterface in /repo/magento/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php:50
Stack trace:
#0 /repo/magento/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Vendor\\SomeService\\Fact...')
#1 /repo/magento/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php(144): Magento\Framework\ObjectManager\ObjectManager->get('Vendor\\SomeService\\Fact...')
#2 /repo/magento/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php(230): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Vendor\\SomeService\\Fact...', NULL, 'someServiceFactory', 'MyCompany\\SomeOtherModule...')
#3 /repo/magento/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime('MyCompany\\SomeOtherModule...', Array, Array)
#4 /repo/magento/l in /repo/magento/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php on line 50

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question