[英]How to configure Doctrine Entity Manager as a public Symfony service?
我想将Doctrine Entity Manager配置为公共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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.