title: Why ninject gets different Db instances in nunit?
body: <p>I write integration tests for ASP.NET MVC based application, and I try to resolve ninject registration issue.</p>
  
  <p>So for my ASP.NET MVC registration I have </p>
  
  <pre><code> kernel.Bind(typeof(ICustomDbContext), typeof(IUnitOfWork))
                  .ToMethod(ctx =&gt; ctx.Kernel.Get&lt;CustomDbContext&gt;())
                  .InRequestScope();
  </code></pre>
  
  <p>Just to clarify  CustomDbContext implements IUnitOfWork and ICustomDbContext.<br>
  With that registration i guarantee that i have one unique instance per request for CustomDbContext. That registration works properly in scope of ASP.NET.</p>
  
  <p>The problem is when i write integration tests.
  <br></p>
  
  <pre><code>[SetUp]
  public void SetUp()
  {
      kernel = NinjectConfig.CreateKernel();
  }
  
  
  [Test]
  public async Task Test()
  {
      // Arrange
      var claaService = kernel.Get&lt;IService&gt;();
  
  }
  </code></pre>
  
  <p>On set up step i load my composition root (which is in ASP.NET MVC project).</p>
  
  <p><br>
  The problem is when i get IService (Implementation of IService.cs is Service.cs and that service has dependencies to IUnitOfWork.cs and IGenericRepository.cs.  IGenericRepository.cs has dependency to ICustomDbContext). 
  <br>
  At the end when i access IService i should have same instance of CustomDbContext (and as I said in works in scope of MVC). 
  <br>I have tried  to resolve it in child scope, but the result is the same (they still have different hash code):</p>
  
  <pre><code>using (var childKernel1 = new ChildKernel(kernel))
  {
      childKernel1.Rebind(typeof(ICustomDbContext), typeof(IUnitOfWork))
      .ToMethod(ctx =&gt; ctx.Kernel.Get&lt;CustomDbContext&gt;())
      .InThreadScope();
  
      var claaService = childKernel1.Get&lt;IClassService&gt;();
  
  }
  </code></pre>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Why this is happening ?</li>
  <li>How can I resolve it (it works if i do not use ninject, but i want to find a way with Ninject, even if i have to add additional configuration in integration tests) ?</li>
  </ul>