Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Symfony4 MongoDB inject repository

$
0
0

I try to injcect doctrine mongo repository to controller. In services.yaml file I added entry:

    App\Account\Repository\MongoAccountRepository:
    factory: ["@doctrine_mongodb", getRepository]
    arguments:
      - App\Account\Domain\Entity\Account

In my code I want to use repositories hidden behind the interface AccountRepository

class MongoAccountRepository extends DocumentRepository implements AccountRepository {}

When I try to inject repository to controller constructor

class DefaultController extends Controller 
{
     private $accountRepository;

     public function __construct(AccountRepository $accountRepository) {
           $this->accountRepository = $accountRepository;
     }

I get following error:

Argument 1 passed to App\Account\UserInterface\DefaultController::__construct() must implement interface App\Account\Domain\Repository\AccountRepository, instance of Doctrine\ODM\MongoDB\DocumentRepository given

Has someone similar problem?


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>