title: Injecting SecurityContext into a Listener prePersist or preUpdate in Symfony2 to get User in a createdBy or updatedBy Causes Circular Reference Error
body: <p>I setup a listener class where i'll set the ownerid column on any doctrine prePersist. My services.yml file looks like this ... </p>
  
  <pre><code>services:
  my.listener:
      class: App\SharedBundle\Listener\EntityListener
      arguments: ["@security.context"]
      tags:
          - { name: doctrine.event_listener, event: prePersist }
  </code></pre>
  
  <p>and my class looks like this ...</p>
  
  <pre><code>use Doctrine\ORM\Event\LifecycleEventArgs;
  use Symfony\Component\Security\Core\SecurityContextInterface;
  
  class EntityListener
  {
  
  protected $securityContext;
  
  public function __construct(SecurityContextInterface $securityContext)
  {
      $this-&gt;securityContext = $securityContext;
  }
  
  
  /**
   *
   * @param LifecycleEventArgs $args 
   */
  public function prePersist(LifecycleEventArgs $args)
  {
  
      $entity = $args-&gt;getEntity();
      $entityManager = $args-&gt;getEntityManager();
  
      $entity-&gt;setCreatedby();
  
  }
  }
  </code></pre>
  
  <p>The result of this is the following error. </p>
  
  <blockquote>
    <p>ServiceCircularReferenceException: Circular reference detected for service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> my.listener -> security.context -> security.authentication.manager -> fos_user.user_manager".</p>
  </blockquote>
  
  <p>My assumption is that the security context has already been injected somewhere in the chain but I don't know how to access it.  Any ideas? </p>