title: Symfony 5 Can't Inject EntityManagerInterface Into Validator
body: <p>I've just moved to symfony 5 and baffled! I've done this same thing with validators many times with Symfony 4, but now dependency injection of EntityManagerInterface into a custom validator produces this error:</p>
  
  <blockquote>
    <p>Too few arguments to function
    App\Validator\Constraints\UserUsernameConstraintValidator::__construct(),
    0 passed in
    /var/www/appbaseV4/vendor/symfony/validator/ContainerConstraintValidatorFactory.php
    on line 52 and exactly 1 expected</p>
  </blockquote>
  
  <p>The validator class is as follows:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Validator\Constraints;
  
  use App\Entity\User;
  use App\Repository\UserRepository;
  use Doctrine\ORM\EntityManagerInterface;
  use Symfony\Component\Form\Exception\UnexpectedTypeException;
  use Symfony\Component\Validator\Constraint;
  use Symfony\Component\Validator\ConstraintValidator;
  
  class UserUsernameConstraintValidator extends ConstraintValidator
  {
  
      /**
       * @var EntityManagerInterface
       */
      private $em;
  
      /**
       * UserEmailValidator constructor.
       * @param EntityManagerInterface $entityManager
       */
      public function __construct(EntityManagerInterface $entityManager)
      {
          $this-&gt;em = $entityManager;
  
      }
  
      /**
       * @param mixed $value
       * @param Constraint $constraint
       */
      public function validate($value, Constraint $constraint) : void
      {
  
  
          if(!$constraint instanceof UserUsernameConstraint){
              throw new UnexpectedTypeException($constraint,UserUsernameConstraint::class);
          }
  
          if(null === $value || '' === $value){
              return;
          }
  
          if($value != $constraint-&gt;value){
              /** @var UserRepository $repo */
              $repo = $this-&gt;em-&gt;getRepository(User::class);
  
              if($repo-&gt;findOneBy(['username'=&gt;$value])){
                  $this-&gt;context-&gt;buildViolation($constraint-&gt;errorMessage)-&gt;setParameter('username',$value)-&gt;addViolation();
              }
          }
  
      }
  }
  </code></pre>
  
  <p>And then using it in the form type as i always do:</p>
  
  <pre><code>$builder
              -&gt;add('username',TextType::class,[
                  'attr'=&gt;[
                      'class'=&gt;'form-control'
                  ],
                  'required'=&gt;true,
                  'constraints'=&gt;[
                      new UserUsernameConstraint(),
                      new Length([
                          'min'=&gt;6,
                          'max'=&gt;20
                      ]),
  
                  ]
              ])
  </code></pre>
  
  <p>What's going on here? Have they changed this in Symfony 5 because it's just not injecting the entity manager like it normally does when i use symfony 4.</p>