title: FluentValidation - PolymorphicValidator: How to avoid validator duplication?
body: <p>I have an entity called &quot;<strong>Role</strong>&quot; in my asp.net core 6 Web API application. Below is the DTO  of the &quot;<strong>Role</strong>&quot; entity</p>
  <pre><code>public class CreateUpdateRoleDto
  {
      public Guid Id { get; set; }
      .....
  }
  </code></pre>
  <p>and I have implemented the Command like mentioned below</p>
  <pre><code>public class CreateRoleCommand : CreateUpdateRoleDto, IRequest&lt;Guid&gt;
  {
  }
  </code></pre>
  <p>with the corresponding Validator</p>
  <pre><code>public class CreateRoleCommandValidator : AbstractValidator&lt;CreateRoleCommand&gt;
  {
  }
  </code></pre>
  <p>Now, I want to implement the batch processing for the same &quot;<strong>Role</strong>&quot; entity and I have implemented the Command like mentioned below</p>
  <pre><code>public class CreateRoleBatchCommand : CreateUpdateRoleDto, IRequest
  {
  }
  </code></pre>
  <p>with its validator</p>
  <pre><code>public class CreateRoleBatchCommandValidator : AbstractValidator&lt;CreateRoleBatchCommand&gt;
  {
  }
  </code></pre>
  <p><strong>CreateRoleBatchCommandValidator</strong> is just a copy of the <strong>CreateRoleCommandValidator</strong> except that it implements <strong>IRequest</strong> instead of <strong>IRequest</strong> but I don't think we need this additional validator as this is just a duplicate code.</p>
  <p>Below is the implementation of BatchCommand</p>
  <pre><code>public class BatchCommand : IRequest
  {
      public IEnumerable&lt;IRequest&gt; Requests { get; set; }
  }
  </code></pre>
  <p>The batch command validator uses the <strong>PolymorphicValidator</strong> and sets <strong>CreateRoleBatchCommandValidator</strong> as a validator for <strong>CreateRoleBatchCommand</strong>.</p>
  <pre><code>public class BatchCommandValidator : AbstractValidator&lt;BatchCommand&gt;
  {
      public BatchCommandValidator()
      {
          this.RuleForEach(x =&gt; x.Requests).SetAsyncValidator(new PolymorphicValidator&lt;BatchCommand, IRequest&gt;()
          .Add&lt;CreateRoleBatchCommand&gt;(new CreateRoleBatchCommandValidator()));
      }
  }
  </code></pre>
  <p>However, I want to set <strong>CreateRoleCommand</strong> as a validator for <strong>CreateRoleBatchCommand</strong>, something like this</p>
  <pre><code>public class BatchCommandValidator : AbstractValidator&lt;BatchCommand&gt;
  {
      public BatchCommandValidator()
      {
          this.RuleForEach(x =&gt; x.Requests).SetAsyncValidator(new PolymorphicValidator&lt;BatchCommand, IRequest&gt;()
           .Add&lt;CreateRoleBatchCommand&gt;(new CreateRoleCommandValidator()));
      }
  }
  </code></pre>
  <p>However it throws the following error.</p>
  <blockquote>
  <p>CS1503    Argument 1: cannot convert from 'CreateRoleCommandValidator' to
  'FluentValidation.IValidator'</p>
  </blockquote>