title: Symfony custom validator as service
body: <p>Trying to follow the custom validator as as service example from the official docs . I have defined my validator as a service in my "services.yml":</p>
  
  <pre><code>cf.validator.unique.in.system:
              class: 'CF\AppBundle\Validator\Constraints\UniqueInSystemValidator'
              arguments: ['@doctrine']
              tags:
                  - { name: 'validator.constraint_validator', alias: 'cf.validator.unique.in.system' }
  </code></pre>
  
  <p>I have created the neccesary constraint and validator classes:</p>
  
  <p><strong>constraint</strong></p>
  
  <pre><code>namespace CF\AppBundle\Validator\Constraints;
  
  use Symfony\Component\Validator\Constraint;
  
  /**
   * @Annotation
   */
  class UniqueInSystem extends Constraint
  {
      public $message = 'This value is already used.';
  
      public function getTargets()
      {
          return self::CLASS_CONSTRAINT;
      }
  
      public function validatedBy()
      {
          return 'cf.validator.unique.in.system';
      }
  }
  </code></pre>
  
  <p><strong>validator</strong></p>
  
  <pre><code>namespace CF\AppBundle\Validator\Constraints;
  
  use Symfony\Component\Validator\Constraint;
  use Symfony\Component\Validator\ConstraintValidator;
  use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
  
  /**
   * @Annotation
   */
  class UniqueInSystemValidator extends ConstraintValidator
  {
      protected  $em;
  
      public  function  __construct(Doctrine $doctrine)
      {
          $this-&gt;em = $doctrine-&gt;getManager();
      }
      public function validate($subsystem, Constraint $constraint)
      {
  
          1==1; // here is a breakpoint by now
  //        $this-&gt;context-&gt;addViolationAt('[expiresAt].expiresAt', $constraint-&gt;message, ['%string%' =&gt; $value-&gt;format('Y-m-d')] );
      }
  </code></pre>
  
  <p>What I do not understand, is the error message that I get:<code>FatalErrorException: Error: Class '\Symfony\Component\Validator\Constraints\CF\AppBundle\Validators\Constraints\UniqueInSystem' not found in /var/www/escritorio.dev/application/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php line 89</code></p>
  
  <p>Especially this part: <code>'\Symfony\Component\Validator\Constraints\CF\AppBundle\Validators\Constraints\UniqueInSystem'</code>. Why symfony tries to search in this weird namespace? How to avoid this issue?</p>
  
  <h2>UPD</h2>
  
  <p>The validator itself is applied via <code>/src/CF/AppBundle/Resources/config/validation.yml</code>:</p>
  
  <pre><code>CF\AppBundle\Entity\SubSystem:
    constraints:
        - CF\AppBundle\Validators\Constraints\UniqueInSystem: ~
    properties:
      name:
        - NotBlank: ~
        - Length:
            max: 100
      owner:
        - NotBlank: ~
      leader:
        - NotBlank: ~
      system:
        - NotBlank: ~
      status:
        - NotBlank : ~
        - Type:
            type: integer
  </code></pre>
  
  <p>The <code>app/console container:debug</code> output:</p>
  
  <pre><code>$ php app/console container:debug  | grep CF
  auc_helper                                         container CF\AppBundle\Services\AucHelper
  cf.validator.unique.in.system                      container CF\AppBundle\Validator\Constraints\UniqueInSystemValidator
  </code></pre>