Injecting SecurityContext Services into a Listener Class in Symfony2 Causes Circular Reference Error?

I had similar problems and the only workaround was to pass the whole container in the constructor ( arguments: '@service_container' ) use Doctrine\ORM\Event\LifecycleEventArgs; use Symfony\Component\DependencyInjection\ContainerInterface; class MyListener { protected $container; public function __construct(ContainerInterface $container) { $this->container = $container; } // ... public function prePersist(LifeCycleEventArgs $args) { $securityContext = $this->container->get('security. Context'); // ... } }.

I had similar problems and the only workaround was to pass the whole container in the constructor (arguments: '@service_container'). Use Doctrine\ORM\Event\LifecycleEventArgs; use Symfony\Component\DependencyInjection\ContainerInterface; class MyListener { protected $container; public function __construct(ContainerInterface $container) { $this->container = $container; } // ... public function prePersist(LifeCycleEventArgs $args) { $securityContext = $this->container->get('security. Context'); // ... } }.

Good call, I ended up trying all sorts of things the day I asked the question and finally wound up getting it working after passing in the Container. In hindsight the error makes a little more sense. – Jeremy Sep 29 at 22:05 @Jeremy: I never really figured out why should one get a circular reference exception by passing individual services.

Why would it make sense? – gilden Sep 29 at 23:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions