1
1
1alexandr2016-03-07 09:49:06
symfony
1alexandr, 2016-03-07 09:49:06

Why can't I inject a repository as a service in symfony3?

Hello. Please help me figure out why it is not possible to inject the repository into the service as a dependency? I am using symfony3. In symfony2.8 this worked...

app.repository.product:
        class: AppBundle\Repository\ProductRepository
        factory_service: doctrine.orm.entity_manager
        factory_method: getRepository
        arguments: ["AppBundle:Product"]

app.controller.product:
        class: AppBundle\Controller\ProductController
        arguments: ["@form.factory", "@app.repository.product"]

Exhaust:
Catchable Fatal Error: Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given....

Problem solved. Here is a working version.
app.repository.product:
        class: AppBundle\Repository\ProductRepository
        factory: ["@doctrine.orm.default_entity_manager", getRepository]
        arguments: [AppBundle\Entity\Product]

Thanks for the help Egor

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor, 2016-03-07
@1alexandr

I can be wrong, because. did not work with 3.0. But the way given in your example was valid in 2.3 and 2.7. Try to do like here . As evidenced by the comments from Matthias Noback 's post .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question