title: Pass user in argument as dependence injection - symfony4
body: <blockquote>
    <p>Error: "Cannot resolve argument $experienceCalculator of "App\Controller\StudyActivityController::create()": Cannot autowire service "App\Service\ExperienceCalculator": argument "$user" of method "__construct()" references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. Did you create a class that implements this interface?"</p>
  </blockquote>
  
  <p>I'm working on an api and I need to access the user in a service that I'm passing as dependency injection in the controller. If I access the user in the controller it works fine but in the service not.</p>
  
  <pre><code>// src/Controller/StudyTimeController.php
  
  public function create(
      Request $request,
      UserInterface $user,
      ExperienceCalculator $experienceCalculator
  )
  {
      $experienceCalculator-&gt;calculate();
  }
  </code></pre>
  
  <p>It seems that autowiring isn't finding the UserInterface  when passing in the constructor of the service.</p>
  
  <pre><code>// src/Service/ExperienceCalculator.php
  
  public function __construct(
      StudyTimeRepository $studyTimeRepository,
      UserInterface $user
  )
  {
      $this-&gt;studyTimeRepository = $studyTimeRepository;
      $this-&gt;user = $user;
  }
  </code></pre>
  
  <p>So what I did was add an alias in configs so the service know which class is been passed, that worked but the user isn't populated.</p>
  
  <pre><code># config/services.yaml
  
  App\Entity\User: ~
  Symfony\Component\Security\Core\User\UserInterface: '@App\Entity\User'
  </code></pre>
  
  <p>I don't know if thats relevant but I'm using this bundle <a href="https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/1-configuration-reference.md" rel="nofollow noreferrer">LexikJWTAuthenticationBundle</a> to authenticate the user.</p>