简体   繁体   English

如何将Doctrine Entity Manager配置为公共Symfony服务?

[英]How to configure Doctrine Entity Manager as a public Symfony service?

I'd like to configure Doctrine Entity Manager as a public Symfony service. 我想将Doctrine Entity Manager配置为公共Symfony服务。

I tried adding the following configuration blocks in services.yml (one at a time): 我尝试在services.yml添加以下配置块(一次一个):

Doctrine\ORM\EntityManagerInterface:                                                                                
    public: true            
# [OUTPUT] Error: Cannot instantiate interface Doctrine\ORM\EntityManagerInterface                                                                       

Doctrine\ORM\EntityManager:                                                                                         
    public: true                                                                                                    
# [OUTPUT] Invalid service "Doctrine\ORM\EntityManager": its constructor must be public.

doctrine.orm.default_entity_manager:                                                                                
    public: true  
# [OUTPUT] The definition for "doctrine.orm.default_entity_manager" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.

Judging by the output error messages, I suspect that the definitions are incomplete, but I didn't find anywhere the correct way to manually configure the Doctrine Entity Manager service. 从输出错误消息判断,我怀疑定义是不完整的,但我没有找到正确的方法来手动配置Doctrine Entity Manager服务。

As per Cerad's comment, I had to add alias: 'doctrine.orm.default_entity_manager' to my first attempted configuration. 根据Cerad的评论,我不得不在我的第一次尝试配置中添加alias: 'doctrine.orm.default_entity_manager'

So the correct solution is: 所以正确的解决方案是:

Doctrine\ORM\EntityManagerInterface:                                                                                
    public: true
    alias: 'doctrine.orm.default_entity_manager'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM