【问题标题】:How to inject @session service to custom EntityManager in Symfony2如何在 Symfony2 中将 @session 服务注入到自定义 EntityManager
【发布时间】:2012-05-31 16:05:19
【问题描述】:

在我的配置文件中,我定义了自定义实体管理器:

parameters:
    doctrine.orm.entity_manager:
        class: Strict\UserBundle\Entity\Manager\MyEntityManager

是否可以将@session 服务(我需要访问 getLocale() 方法)注入/添加到此实体管理器中? 我试过这个:

parameters:
    doctrine.orm.entity_manager:
        class: Strict\UserBundle\Entity\Manager\MyEntityManager
        arguments: 
            session: "@session"

但它会抛出这个异常:

InvalidArgumentException: You cannot dump a container with parameters that contain references to other services (reference to service "session" found in "/doctrine.orm.entity_manager/arguments/session").

有什么想法吗?

【问题讨论】:

    标签: symfony


    【解决方案1】:

    参数不允许服务作为参数,您是否尝试过做同样的事情但使用服务:

    service:
       my.entity.manager:
          class: Strict\UserBundle\Entity\Manager\MyEntityManager
          arguments: 
            session: "@session"
    

    【讨论】:

    • 效果很好 - 我忘了服务:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多