3

1 exception(s): Exception #0 (RuntimeException):

Source class "\Vendor\ModuleName\Model\ResourceModel\CapabilityInterface" 
  for "Vendor\ModuleName\Model\ResourceModel\CapabilityRepository" 
  generation does not exist.

where as in my di.xml I have mentioned

<preference for="Vendor\ModuleName\Api\CapabilityRepInterface"
            type="Vendor\ModuleName\Model\ResourceModel\CapabilityRepository" />

when I run

php bin/magento setup:di:compile

It doesn't give any error but when i inject this interface in my controller the above error is shown.

use Magento\Backend\App\Action;
use Magento\Framework\App\ResponseInterface;
use Vendor\ModuleName\Api\CapabilityRepInterface;

class Temp extends Action
{
protected $capabiliyRepo;

public function __construct(
    Action\Context $context,
    CapabilityRepInterface $capabilityRep
)
{
    parent::__construct($context);
    $this->capabiliyRepo = $capabilityRep;
}

public function execute()
{
    $this->capabiliyRepo->checkAbility("my_project_create_project");
}
}
8
  • can you include your controller in your post
    – fmsthird
    Apr 18, 2019 at 6:26
  • Added please check
    – Avesh Naik
    Apr 18, 2019 at 6:30
  • @magefms i have added the controller. can you check now?
    – Avesh Naik
    Apr 18, 2019 at 6:58
  • Is that the whole code of your controller? try changing to return $this->capabiliyRepo->checkAbility("my_project_create_project"); instead of $this->capabiliyRepo->checkAbility("my_project_create_project");
    – fmsthird
    Apr 18, 2019 at 7:07
  • try this instead use Magento\Framework\App\ResponseInterface; use Vendor\ModuleName\Api\CapabilityRepInterface; class Temp extends \Magento\Backend\App\Action { protected $capabiliyRepo; public function __construct( Action\Context $context, CapabilityRepInterface $capabilityRep ) { parent::__construct($context); $this->capabiliyRepo = $capabilityRep; } public function execute(){ return $this-> capabiliyRepo->checkAbility("my_project_create_project"); } }
    – fmsthird
    Apr 18, 2019 at 7:11

1 Answer 1

-1

I think you need to change the path of the Repository class. It should be under root of Model directory.

<preference for="Vendor\ModuleName\Api\CapabilityRepositoryInterface"
            type="Vendor\ModuleName\Model\CapabilityRepository" />

You can also check the Magento core repository for reference.

/vendor/magento/module-catalog/Model/CategoryRepository.php

4
  • Same error. Source class "\Vendor\ModuleName\Model\CapabilityInterface" for "Vendor\ModuleName\Model\CapabilityRepository" generation does not exist.
    – Avesh Naik
    Apr 18, 2019 at 6:07
  • CapabilityRepository class should implements the CapabilityRepositoryInterface. Can you double confirm ? Apr 18, 2019 at 6:10
  • class CapabilityRepository implements \Vendor\ModuleName\Model\CapabilityInterface, please check that you added \ in-front of the interface. Apr 18, 2019 at 6:15
  • CapabilityRepository class should implements the CapabilityRepositoryInterface. Yes i implemented it.
    – Avesh Naik
    Apr 18, 2019 at 6:18

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.