3

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?

Luke
  • 20,878
  • 35
  • 119
  • 178

1 Answers1

6

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>
kapa89
  • 607
  • 3
  • 13
  • Ah. Basically pretty much the same as configuring the ORM. Thanks. – Luke Jul 19 '14 at 23:17
  • 1
    And here is the related doc: http://symfony.com/doc/current/components/dependency_injection/factories.html – j0k Jan 30 '15 at 10:14