如何在Symfony2中将@session服务注入自定义实体管理器



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

parameters:
    doctrine.orm.entity_manager:
        class: StrictUserBundleEntityManagerMyEntityManager
是否是一种将

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

parameters:
    doctrine.orm.entity_manager:
        class: StrictUserBundleEntityManagerMyEntityManager
        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").

有什么想法吗?

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

service:
   my.entity.manager:
      class: StrictUserBundleEntityManagerMyEntityManager
      arguments: 
        session: "@session"

最新更新