title: How to use Ninject to create instances in child classes?
body: <p>I am learning how to use nInject for a new application I am developing, and I have created the following sample code that can be copied/pasted into a simple console app.  It successfully returns an instance of IFoo, but I have a question about it.</p>
  
  <p>How would I modify the code to have the FooManager class create an instance of the Foo object without doing a 'new'.  Does the kernal have to be injected as well?  But if the kernal is injected and I change the line to read <code>var foo = _kernel.Get&lt;IFoo&gt;()</code>, isn't that introducing a service locator anti-pattern?</p>
  
  <pre><code>namespace IOCTest
  {
      class Program
      {
          static void Main(string[] args)
          {
              using (IKernel kernel = new StandardKernel(new StandardModule()))
              {
                  // do something with the kernal
                  var mgr = kernel.Get&lt;IFooManager&gt;();
                  var foo = mgr.GetById(1);
              }
          }
      }
  
      public class StandardModule : Ninject.Modules.NinjectModule
      {
          public override void Load()
          {
              Bind&lt;IDatabase&gt;()
                  .To&lt;Database&gt;()
                  .InTransientScope();
  
              Bind&lt;IFooManager&gt;()
                  .To&lt;FooManager&gt;()
                  .InTransientScope();
          }
      }
  
      //******************************************************
  
      public interface IDatabase
      {
          object[] GetScalar(int id);
      }
  
      public class Database : IDatabase
      {
          public object[] GetScalar(int id)
          {
              return new object[] { "RowName" };
          }
      }
  
      //******************************************************
  
      public interface IFooManager
      {
          IFoo GetById(int id);
      }
  
      public class FooManager : IFooManager
      {
          private IDatabase _db;
  
          public FooManager(IDatabase db) { _db = db; }
  
          public IFoo GetById(int id)
          {
              var results = _db.GetScalar(id);
              var foo = new Foo();   // &lt;-- HOW DO I ELIMINATE THIS DEPENDENCY?
              foo.Name = results[0].ToString();
              return foo;
          }
      }
  
      //******************************************************
  
      public interface IFoo
      {
          string Name { get; set; }
      }
  
      public class Foo : IFoo
      {
          public string Name { get; set; }
      }
  
      //******************************************************
  }
  </code></pre>