Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up a Doctrine MongoDB respository in the Symfony 2 service container

How do I correctly set up the service container in my Symfony 2 application to support custom Document repositories?

What I have so far is:

services:
  acme.repository_user:
    class: Acme\Repository\UserRepository
    arguments: [@doctrine.odm.mongodb.document_manager]

However, when I look at the constructor of the DocumentRepository class, of which my UserRepository inherits, I can see the following arguments:

public function __construct(DocumentManager $dm, UnitOfWork $uow, Mapping\ClassMetadata $class)

I seem to have injected the document manager but how do I inject the Unit of Work and the class meta data?

like image 800
Luke Avatar asked Oct 12 '25 18:10

Luke


1 Answers

Try to define service as(sorry for xml):

<service id="acme.repository_user"
             class="Acme\Repository\UserRepository"
             factory-service="doctrine.odm.mongodb.document_manager"
             factory-method="getRepository"
             public="false">
    <argument>AcmeBundle:User</argument>
</service>
like image 188
kapa89 Avatar answered Oct 14 '25 07:10

kapa89