title: Symfony 3 error when injecting entity manager into event listener
body: <p>I have an event listener that sets up some session variables and also checks if a visitor has set a type of shopping cart on a previous visit and shows its details on the front end. </p>
  
  <p>The event was working fine till a tried to inject the entity manager, from which I need to use some setters/getters on the Visitor entity.  </p>
  
  <p>I also tried <a href="https://stackoverflow.com/questions/30479180/how-to-get-container-object-from-lifecycleeventargs-of-postload-in-entity">this solution</a> but ended up with the same issue of 'string given' instead of the object. </p>
  
  <p>The error it produces is:</p>
  
  <blockquote>
    <p>Type error: Argument 2 passed to AppBundle\EventListener\InitializerListener::onKernelRequest() must be an instance of Doctrine\ORM\EntityManager, string given</p>
  </blockquote>
  
  <p>This is the code:]</p>
  
  <p>services.yml </p>
  
  <pre><code>  app.initializer_listener:
    class: AppBundle\EventListener\InitializerListener
    arguments: ["@doctrine.orm.entity_manager"]
    tags:
      - { name: kernel.event_listener, event: kernel.controller, method: onKernelRequest }
  </code></pre>
  
  <p>AppBundle\EventListener\IniatilizerListener</p>
  
  <pre><code>namespace AppBundle\EventListener;
  
  use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  use Symfony\Component\HttpFoundation\Cookie;
  use Symfony\Component\HttpFoundation\Response;
  use UsedBundle\Entity\Visitor;
  use Doctrine\Common\Persistence\ManagerRegistry;
  use Doctrine\ORM\EntityManager;
  
  class InitializerListener
  {
  private $event;
  private $em;
  
  public function onKernelRequest( FilterControllerEvent $event, EntityManager $em )
  {   
      $visitor = new Visitor();
  
      $this-&gt;em = $em;
  
      $route = $event-&gt;getRequest()-&gt;get('_route');
      if ($event-&gt;isMasterRequest() &amp;&amp; '_wdt' !== $route ) {
          $session = $event-&gt;getRequest()-&gt;getSession();
          $cookies = $event-&gt;getRequest()-&gt;cookies;
          $this-&gt;sessionInit( $session, $cookies );
          //$this-&gt;visitorInit( $session, $cookies, $visitor );
          //$em-&gt;persist($visitor);
          //$em-&gt;flush();
      }
  }
  
  private function sessionInit( $session, $cookies )
  {
      $session-&gt;set('active', time() );
      $session-&gt;has('page_ct') ? $session-&gt;set('page_ct', $session-&gt;get('page_ct') + 1 ): $session-&gt;set('page_ct', 1 );
  }
  
  private function visitorInit($session, $cookies, $visitor)
  {
     //visitor setup/shopping cart here
  }
  }
  </code></pre>