4

I have added a Repository interface in my Api directory and it's implementation in located under Models directory.

I have setup the preference for the interface in etc/di.xml.

When I run bin/magento setup:di:compile the following error is thrown in the console.

Source class "\Namespace\Module\Model\PostInterface" for "Namespace\Module\Model\PostRepository" generation does not exist.

I have no idea why the system is searching for "\Namespace\Module\Model\PostInterface" while I have mentioned clearly the location of the implementation class in di.xml.

Any suggestions are welcome with thanks !!

More Info:

When I remove the Repository implementation file i.e; app/code/Namespace/Module/Model/PostRepository.php (imlpements app/code/Namespace/Module/Api/PostRepositoryInterface.php), the error disappears.

Also, when I rename the file from app/code/Namespace/Module/Model/PostRepository.php to app/code/Namespace/Module/Model/PostRepositoryy.php, the error disappears.

Is there any conventions that needs to be followed while using Repositories ?

  • I get the same error and removing or renaming the file does not help. It's crazy. – Matt Cosentino Sep 18 '17 at 15:25
2

After a lot of Code analysis and Google searches, I found the fix for this problem. Adding the following to the di.xml fixed this issue.

<type name="Magento\Framework\Model\Entity\RepositoryFactory">
        <arguments>
            <argument name="entities" xsi:type="array">
                <item name="Namespace\Module\Api\Data\PostInterface" xsi:type="string">Namespace\Module\Api\Data\PostRepositoryInterface
                </item>
            </argument>
        </arguments>
    </type>
1

Remove var/generation and var/di folders Then try again with command

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy
  • I have followed these steps and the error still appears. – N. Karthic Kannan Mar 23 '17 at 6:46
0

This is an old post now, but for anyone else that's still experiencing this, a fix that seems to work is rather than defining the repository interface as a use statement, add its fully qualified name, for example:

use Vendor\Module\Interface;

class MyClass implements Interface

Becomes:

class MyClass implements \Vendor\Module\Interface

This fixed this for us when compiling repositories on M2 2.2.3

0

I've had this error after trying to generate di and it even persisted on any cli command for some reason.

Try to delete generated/*

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.