title: Castle Windsor - How to map Named instance in constructor injection
body: <p>maybe this is easy, but searching it on the internet already give me a head ache</p>
  
  <p>here is the problem:</p>
  
  <pre><code>interface IValidator
  {
      void Validate(object obj);
  }
  
  public class ValidatorA : IValidator
  {
      public void Validate(object obj) { }
  }
  
  public class ValidatorB : IValidator
  {
      public void Validate(object obj) { }
  }
  
  
  interface IClassA { }
  interface IClassB { }
  
  public class MyBaseClass
  {
      protected IValidator validator;
  
      public void Validate()
      {
          validator.Validate(this);
      }
  }
  
  public class ClassA : MyBaseClass, IClassA
  {
      //problem: validator should ValidatorA
      public ClassA(IValidator validator) { }
  }
  
  public class ClassB : MyBaseClass, IClassB
  {
      //problem: validator should ValidatorB
      public ClassB(IValidator validator) { }
  }
  
  public class OtherClass
  {
      public OtherClass(IClassA a, IClassB b) { }
  }
  
  
  //on Main
  var oc = container.Resolve&lt;OtherClass&gt;();
  </code></pre>
  
  <p>Any idea? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I registered <code>ValidatorA</code> and <code>ValidatorB</code> with <code>Named</code>, now the problem how Castle Windsor can inject those validator properly to the <code>ClassA</code> and <code>ClassB</code>, is there a way to do that? or is there any better solution?</p>
  
  <p>if there is someone think my class design is wrong please, i open for any advice. So far i think it correct. Yes, validator have specific configuration for specific Class. but there are reasons it is abstracted:</p>
  
  <ol>
  <li>Validator is a complex object, sometime should connect to database, so I MUST pass interface instead of implementation to constructor for unit testing reason.</li>
  <li>No way to use different interface for any of Validator, because the only method that i used is <code>Validate</code></li>
  <li>I think <code>MyBaseClass.Validate()</code> a common <strong>template method</strong> pattern isn't it?</li>
  </ol>