title: You have requested a non-existent service "security.context"
body: <p>i create service but it doesn't work</p>
  
  <pre><code>services:
      redirectionListener:
            class: Front\EcommerceBundle\Listener\RedirectionListener
            arguments: ["@service_container","@session"]
            tags:
              - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
  </code></pre>
  
  <p>and this my class
      
  
  <pre><code>namespace Front\EcommerceBundle\Listener;
  
  use Symfony\Component\DependencyInjection\ContainerBuilder;
  use Symfony\Component\HttpFoundation\Session\Session;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  
  class RedirectionListener
  {
      public function __construct(ContainerBuilder $container, Session $session)
      {
          $this-&gt;session = $session;
          $this-&gt;router = $container-&gt;get('router');
          $this-&gt;securityContext = $container-&gt;get('security.context');
      }
  
      public function onKernelRequest(GetResponseEvent $event)
      {
          $route = $event-&gt;getRequest()-&gt;attributes-&gt;get('_route');
  
          if ($route == 'livraison' || $route == 'validation') {
              if ($this-&gt;session-&gt;has('panier')) {
                  if (count($this-&gt;session-&gt;get('panier')) == 0)
                      $event-&gt;setResponse(new RedirectResponse($this-&gt;router-&gt;generate('panier')));
              }
  
              if (!is_object($this-&gt;securityContext-&gt;getToken()-&gt;getUser())) {
                  $this-&gt;session-&gt;getFlashBag()-&gt;add('notification','Vous devez vous identifier');
                  $event-&gt;setResponse(new RedirectResponse($this-&gt;router-&gt;generate('fos_user_security_login')));
              }
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>ServiceNotFoundException in Container.php line 268: You have requested
    a non-existent service "security.context".</p>
  </blockquote>