title: Dependency Injection with Interface implemented by multiple classes
body: <p><strong>Update:</strong> Is there a way to achieve what I'm trying to do in an IoC framework other than Windsor? Windsor will handle the controllers fine but won't resolve anything else. I'm sure it's my fault but I'm following the tutorial verbatim and objects are not resolving with ctor injection, they are still null despite doing the registers and resolves. I've since scrapped my DI code and have manual injection for now because the project is time sensitive. Hoping to get DI worked out before deadline.</p>
  
  <hr>
  
  <p>I have a solution that has multiple classes that all implement the same interface</p>
  
  <p>As a simple example, the <code>Interface</code></p>
  
  <pre><code>public interface IMyInterface {
      string GetString();
      int GetInt();
     ...
  }
  </code></pre>
  
  <p>The concrete classes</p>
  
  <pre><code>public class MyClassOne : IMyInterface {
      public string GetString() {
          ....
      }
      public int GetInt() {
          ....
      }
  }
  
  public class MyClassTwo : IMyInterface {
      public string GetString() {
          ....
      }
      public int GetInt() {
          ....
      }
  }
  </code></pre>
  
  <p>Now these classes will be injected where needed into layers above them like:</p>
  
  <pre><code>public class HomeController {
  
      private readonly IMyInterface myInterface;
  
      public HomeController() {}
  
      public HomeController(IMyInterface _myInterface) {
          myInterface = _myInterface
      }
      ...
  }
  
  public class OtherController {
  
      private readonly IMyInterface myInterface;
  
      public OtherController() {}
  
      public OtherController(IMyInterface _myInterface) {
          myInterface = _myInterface
      }
      ...
  }
  </code></pre>
  
  <p>Both controllers are getting injected with the same interface.</p>
  
  <p>When it comes to resolving these interfaces with the proper concrete class in my IoC, how do I differentiate that <code>HomeController</code> needs an instance of <code>MyClassOne</code> and <code>OtherController</code> needs an instance of <code>MyClassTwo</code>?</p>
  
  <p>How do I bind two different concrete classes to the same interface in the IoC? I don't want to create 2 different interfaces as that breaks the DRY rule and doesn't make sense anyway.</p>
  
  <p>In Castle Windsor I would have 2 lines like this:</p>
  
  <pre><code>container.Register(Component.For&lt;IMyInterface&gt;().ImplementedBy&lt;MyClassOne&gt;());
  container.Register(Component.For&lt;IMyInterface&gt;().ImplementedBy&lt;MyClassTwo&gt;());
  </code></pre>
  
  <p>This won't work because I will only ever get a copy of <code>MyClassTwo</code> because it's the last one registered for the interface. </p>
  
  <p>Like I said, I don't get how I can do it without creating specific interfaces for each concrete, doing that breaks not only DRY rules but basic OOP as well. How do I achieve this?</p>
  
  <hr>
  
  <p><strong>Update based on Mark Polsen's answer</strong></p>
  
  <hr>
  
  <p>Here is my current IoC, where would the <code>.Resolve</code> statements go? I don' see anything in the Windsor docs</p>
  
  <pre><code>public class Dependency : IDependency {
  
      private readonly WindsorContainer container = new WindsorContainer();
  
      private IDependency() {
      }
  
      public IDependency AddWeb() {
          ...
  
          container.Register(Component.For&lt;IListItemRepository&gt;().ImplementedBy&lt;ProgramTypeRepository&gt;().Named("ProgramTypeList"));
          container.Register(Component.For&lt;IListItemRepository&gt;().ImplementedBy&lt;IndexTypeRepository&gt;().Named("IndexTypeList"));
  
          return this;
      }
  
      public static IDependency Start() {
          return new IDependency();
      }
  }
  </code></pre>