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

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

我想将 Doctrine Entity Manager 配置为 public Symfony 服务。

我尝试在 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.

从输出的错误消息来看,我怀疑定义不完整,但我没有在任何地方找到手动配置 Doctrine Entity Manager 服务的正确方法。

根据 Cerad 的评论,我不得不添加 alias: 'doctrine.orm.default_entity_manager' 到我第一次尝试的配置。

所以正确的解法是:

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