title: Ninject Overriding Bindings
body: <p>From the tutorial referenced below, there is a controller:</p>
  
  <pre><code>public class HomeController : Controller
  {
    MvcNinjectExample.Logging.ILogger _logger;
  
    public HomeController(MvcNinjectExample.Logging.ILogger logger)
    {
      _logger = logger;
    }
  
    public ActionResult Index()
    {
      _logger.LogMessage("Running index page!");
  
      return Content("Message logged");
    }
  }
  </code></pre>
  
  <p>As per the following binding...</p>
  
  <pre><code>public static void RegisterServices(IKernel kernel)
  {
    kernel.Bind&lt;ILogger&gt;().To&lt;TextFileLogger&gt;();
  }
  </code></pre>
  
  <p>... The <strong>TextFileLogger()</strong> is called whenever the <code>HomeController</code> is instantiated.  Correct?</p>
  
  <p>The tutorial goes on to say this:</p>
  
  <blockquote>
    <p>If you were to change this to use our EventFileLogger implementation as in one of the earlier examples, you will see that all you would have to do is create the implementation, make it implement ILogger and then register it in your kernel bindings. <strong>No changes to any controllers which use it are necessary.</strong></p>
  </blockquote>
  
  <h3>My question is:</h3> 
  
  <p>If I created a new class called <code>EventFileLogger()</code> which implemented <code>ILogger</code> and then created the binding like <code>kernel.Bind&lt;ILogger&gt;().To&lt;EventFileLogger&gt;();</code>, how does Ninject know to use my new <code>EventFileLogger()</code> and not the other binding for <code>TextFileLogger()</code> when the <code>HomeController</code> is instantiated?</p>
  
  <p>Ref. <a href="http://stevescodingblog.co.uk/dependency-injection-beginners-guide/" rel="nofollow">http://stevescodingblog.co.uk/dependency-injection-beginners-guide/</a></p>