0

I'm trying to create a custom module for Magento 2. when I try to inject the ThreadRepositoryInterface into the controller constructor the code fails.

This is the error:

Fatal error: Uncaught Error: Cannot instantiate interface Mycompany\Tickets\Api\ThreadRepositoryInterface in /var/www/html2/magento2.local/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php on line 73

this is the structure of the module:

.
├── Api
│   ├── AttachmentRepositoryInterface.php
│   ├── CategoryRepositoryInterface.php
│   ├── Data
│   │   ├── AttachmentInterface.php
│   │   ├── AttachmentSearchResultsInterface.php
│   │   ├── CategoryInterface.php
│   │   ├── CategorySearchResultsInterface.php
│   │   ├── StatusInterface.php
│   │   ├── StatusSearchResultsInterface.php
│   │   ├── ThreadInterface.php
│   │   ├── ThreadSearchResultsInterface.php
│   │   ├── TicketsInterface.php
│   │   └── TicketsSearchResultsInterface.php
│   ├── StatusRepositoryInterface.php
│   ├── ThreadRepositoryInterface.php
│   └── TicketsRepositoryInterface.php
├── Block
│   ├── Create
│   │   └── Form.php
│   ├── Index
│   │   └── Tickets.php
│   └── Reply
│       └── Index.php
├── composer.json
├── Controller
│   ├── Create
│   │   └── Index.php
│   ├── Index
│   │   ├── Fastlink.php
│   │   └── Index.php
│   └── Reply
│       └── Index.php
├── etc
│   ├── acl.xml
│   ├── adminhtml
│   │   ├── menu.xml
│   │   ├── routes.xml
│   │   └── system.xml
│   ├── config.xml
│   ├── di.xml
│   ├── email_templates.xml
│   ├── frontend
│   │   └── routes.xml
│   ├── module.xml
│   └── webapi.xml
├── Helper
│   ├── AbstractData.php
│   └── Data.php
├── LICENSE.txt
├── Model
│   ├── Attachment
│   │   └── DataProvider.php
│   ├── Attachment.php
│   ├── AttachmentRepository.php
│   ├── Category
│   │   └── DataProvider.php
│   ├── Category.php
│   ├── CategoryRepository.php
│   ├── Config
│   │   └── Source
│   │       └── Tickets
│   │           └── Status.php
│   ├── ResourceModel
│   │   ├── Attachment
│   │   │   └── Collection.php
│   │   ├── Attachment.php
│   │   ├── Category
│   │   │   └── Collection.php
│   │   ├── Category.php
│   │   ├── Status
│   │   │   └── Collection.php
│   │   ├── Status.php
│   │   ├── Thread
│   │   │   └── Collection.php
│   │   ├── Thread.php
│   │   ├── Tickets
│   │   │   └── Collection.php
│   │   └── Tickets.php
│   ├── Sendmail.php
│   ├── Status
│   │   └── DataProvider.php
│   ├── Status.php
│   ├── StatusRepository.php
│   ├── Thread
│   │   └── DataProvider.php
│   ├── Thread.php
│   ├── ThreadRepository.php
│   ├── Tickets
│   │   └── DataProvider.php
│   ├── Tickets.php
│   ├── TicketsRepository.php
│   └── TicketsSearchResult.php
├── registration.php
├── Setup
│   ├── InstallData.php
│   └── InstallSchema.php
└── view
    └── frontend
        ├── email
        │   └── ticket_new.html
        ├── layout
        │   ├── customer_account.xml
        │   ├── tickets_create_index.xml
        │   ├── tickets_index_fastlink.xml
        │   ├── tickets_index_index.xml
        │   └── tickets_reply_index.xml
        └── templates
            ├── form
            │   ├── register.phtml
            │   └── reply.phtml
            └── list.phtml

36 directories, 76 files

Any idea?

1 Answer 1

0

If you have created your own module/template and the Resolver doesn't resolve one of your Api interface you have to add the specific preference in the di.xml file located into your module.

For instance:

<preference for="Yourcompany\Yourmodule\Api\Data\YourInterface" type="Yourcompany\Yourmodule\Model\Yourmodel"/>

then you have to execute the shell command to clean up your magento cache:

rm -rf var/di var/generation pub/static/frontend var/view_preprocessed var/page_cache/ var/cache/

or simply:

php bin/magento setup:upgrade 

and now the interface will be resolved!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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