title: DI with Ninject in a Class Library
body: <p>I'm successfully using Ninject in my web applications by deriving my Global from <code>NinjectHttpApplication</code> and using the <code>NinjectHttpModule</code> in my web.config</p>
  
  <p>What I want to do now is using DI in one of my class libraries and I don't know how to go about this.  I have the following dummy class:</p>
  
  <pre class="lang-c# prettyprint-override"><code>/// &lt;summary&gt;
  /// Testing Ninject DI in a class library
  /// &lt;/summary&gt;
  public class Class1
  {
      [Inject]
      ICustomerRepository CustomerRepository { get; set; }
  
      public string SomeText { get; set; }
  
      public Class1(string text)
      {
          MyConfig config = new MyConfig();
          config.Configure();
  
          SomeText = text;
      }
  
      public Customer GetCustomer()
      {
          var customer = CustomerRepository.GetCustomer();
          return customer;
      }
  }
  
  public class MyConfig
  {
      public IKernel Configure()
      {
          IKernel kernel = new StandardKernel(new NinjectRepositoryModule());
          return kernel;
      }
  }
  </code></pre>
  
  <p>When I instantiate <code>Class1</code> and call <code>GetCustomer()</code>, the <code>CustomerRepository</code> is null, so I'm obviously doing something wrong.</p>
  
  <p>Also, if I use constructor injection and have my constructor like</p>
  
  <pre class="lang-c# prettyprint-override"><code>public Class1([Inject] ICustomerRepository repository)
  </code></pre>
  
  <p>how would I go about instantiating <code>Class1</code>?</p>
  
  <p>Quite new to Ninject, so this could all be very easy stuff.</p>