title: Self-binding with Simple Injector
body: <p>I'm trying to learn dependency injection with Simple Injector so I've created a simple program. I looked through tons of examples, but didn't find anything similar to this. Ninject has a similar example and they self-bind the implementation to itself using </p>
  
  <pre><code>Bind&lt;Samurai&gt;().ToSelf();
  </code></pre>
  
  <p>But I didn't find any self-binding examples in simple injector. As it stands the program runs fine and I get expected results I'm looking for, but is it the right way to do it? The program is the last code sample.</p>
  
  <p>Interface </p>
  
  <pre><code>public interface ICar
  {
      void Move(string direction, int distance);
      void Stop();
  }
  </code></pre>
  
  <p>Class</p>
  
  <pre><code>public class Driver
  {
      private readonly ICar _car = null;
  
      public Driver(ICar car)
      {
          this._car = car;
      }
  
      public void Drive(string direction, int distance)
      {
          _car.Move(direction, distance);
      }
  
      public void Brake()
      {
          _car.Stop();
      }
  }
  </code></pre>
  
  <p>Implementations </p>
  
  <pre><code>public class Ferrari : ICar
  {
      public void Move(string direction, int distance)
      {
          Console.WriteLine("I am driving {0} really fast for {1} miles", direction, distance);
      }
      public void Stop()
      {
          Console.WriteLine("I am slamming on the brakes because I'm going too fast");
      }
  }
  
  public class Lexus : ICar
  {
      public void Move(string direction, int distance)
      {
          Console.WriteLine("I am driving {0} for {1} miles", direction, distance);
      }
      public void Stop()
      {
          Console.WriteLine("I am applying the brakes");
      }
  }
  </code></pre>
  
  <p>Program </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var container = new Container();
          container.Options.AllowOverridingRegistrations = true;
  
          container.Register&lt;ICar, Lexus&gt;();
          container.Register&lt;ICar, Ferrari&gt;();
  
          container.Verify();
  
          var johnDoeLexus = new Driver(container.GetInstance&lt;Lexus&gt;());
  
          johnDoeLexus.Drive("North", 10);
          johnDoeLexus.Brake();
  
          var johnDoeFerrari = new Driver(container.GetInstance&lt;Ferrari&gt;());
  
          johnDoeFerrari.Drive("North", 10);
          johnDoeFerrari.Brake();
  
          Console.ReadLine();
      }
  }
  </code></pre>