ninject/ninject.extensions.childkernel — Issue #5: Not correct resolve dependency from child kernel
Author: vvs0205
Created: 2011-12-26 11:40:19+00:00
State: open

Thanks for your project.
I do not know this bug or how it should be.
Here is some code to check for:

public class TestChildKernel
{
[Test]
public void Test()
{
var obj1 = new SomeClass1() { Id = Guid.NewGuid() };
var obj2 = new SomeClass1() { Id = Guid.NewGuid() };
Assert.AreNotEqual(obj1.Id, obj2.Id);

var kernel = new StandardKernel();
kernel.Bind(typeof(ISomeInterface)).To(typeof(SomeClass));
kernel.Bind(typeof(ISomeInterface1)).ToConstant(obj1);
var someClass1 = kernel.Get(typeof(ISomeInterface)) as SomeClass;

var child = new ChildKernel(kernel);
child.Bind(typeof(ISomeInterface1)).ToConstant(obj2);
//if add this it work
// child.Bind(typeof(ISomeInterface)).To();
var someClass2 = child.Get(typeof(ISomeInterface)) as SomeClass;

Assert.AreNotEqual(someClass1.SomeInterface1.Id, someClass2.SomeInterface1.Id);
}
}

public class SomeClass : ISomeInterface
{
public SomeClass(ISomeInterface1 someInterface1)
{
SomeInterface1 = someInterface1;
}

public ISomeInterface1 SomeInterface1 { get; set; }
}

public interface ISomeInterface{}

public interface ISomeInterface1
{
Guid Id { get; set; }
}

public class SomeClass1 : ISomeInterface1
{
public Guid Id { get; set; }
}