title: Ninject, Providers and Activator.CreateInstance
body: <p>I'm fairly new to Ninject, but I have successfully managed to use it for DI using a custom provider. </p>
  
  <p>The binding is initialised as follows</p>
  
  <pre><code>kernel = new StandardKernel();
  
  kernel.Bind&lt;IPatientRecordLocator&gt;().ToProvider&lt;PatientRecordLocatorProvider&gt;();
  </code></pre>
  
  <p>and in the custom provider I call Activator.CreateInstance like so</p>
  
  <pre><code>protected override IPatientRecordLocator CreateInstance(IContext context)
  {
      var name = ConfigurationManager.AppSettings["PatientRecordLocator"];
      var typeName = name.Split(',')[0];
      var assemblyName = name.Split(',')[1];
      return Activator.CreateInstance(assemblyName, typeName).Unwrap() as IPatientRecordLocator;
  }
  </code></pre>
  
  <p>(yes, I am aware that there is no error handling, etc. in the code above :) )</p>
  
  <p>and all this works like a charm. </p>
  
  <p>Now, the problem I'm facing is when I introduce a new class that I wish to inject into instances of IPatientRecordLocator. The problem occurs when I add a constructor like the following to e.g. one of these classes </p>
  
  <pre><code>[Inject]
  public MockPatientRecordLocator (IContactAdapter contactAdapter)
  {
      ...
  }
  </code></pre>
  
  <p>Then, for Activator.CreateInstance to work I also have to add a parameterless constructor to class MockPatientRecordLocator, i.e.</p>
  
  <pre><code>public MockPatientRecordLocator() 
  {
  }
  </code></pre>
  
  <p>So, my question is: how can I make Ninject inject an instance of a class that implements IContactAdapter into e.g. MockPatientRecordLocator? I've tried method injection, but to no avail. </p>
  
  <p>I forgot to explain that what I'm trying to achieve is a kind of chained injection where an instance of class PatientRecordSummary gets injected with an instance of MockPatientRecordLocator (using constructor injection) and said instance of MockPatientRecordLocator should get injected with an instance of IContactAdapter (again using constructor injection (if possible)). The first part of the chain works, the second doesn't.</p>