[英]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? 如何在Symfony 2应用程序中正确设置服务容器以支持自定义文档存储库?
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: 但是,当我查看我的UserRepository
继承的DocumentRepository
类的构造函数时,我可以看到以下参数:
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? 我似乎注入了文档管理器但是如何注入工作单元和类元数据?
Try to define service as(sorry for xml): 尝试将服务定义为(抱歉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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.