Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject @session service to custom EntityManager in Symfony2

Tags:

symfony

In my config file I've defined custom Entity Manager:

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

Is the a way to inject/add @session service (I need to get access to getLocale() method) into this entity manager? I've tried this:

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

but it throws this exception:

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").

Any ideas?

like image 589
Wojciech Jasiński Avatar asked May 31 '12 16:05

Wojciech Jasiński


1 Answers

Parameters don't allow services as arguments, have you tried doing the same thing but using a service:

service:
   my.entity.manager:
      class: Strict\UserBundle\Entity\Manager\MyEntityManager
      arguments: 
        session: "@session"
like image 158
Glen Swinfield Avatar answered Oct 29 '22 05:10

Glen Swinfield