How to inject CUSTOM repository into my service?

456 views Asked by At

I have a custom Stats service, and I want to inject two custom repositories: booksRepository and reviewsRepository into it. How do I do this? When I use this yaml in services.yml, i get two regular repository classes (EntityRepository) instead of my custom repositories in the Stats service constructor.

AppBundle\Services\Stats:
    arguments:
          $booksRepository: '@AppBundle\Repository\BooksRepository'
          $reviewsRepository: '@AppBundle\Repository\ReviewsRepository'
    public: true

AppBundle\Repository\BooksRepository:
    class: AppBundle\Repository\BooksRepository
    factory: ["@doctrine.orm.entity_manager", getRepository]
    arguments:
        - AppBundle\Entity\Books

AppBundle\Repository\ReviewsRepository:
    class: AppBundle\Repository\ReviewsRepository
    factory: ["@doctrine.orm.entity_manager", getRepository]
    arguments:
        - AppBundle\Entity\Reviews

The entites have custom repositories set in annotations.

0

There are 0 answers