-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Description
I'm creating a child kernel and overriding the binding of a specific interface. My expectation is that all dependency resolutions using the child kernel will use this new binding. But, that's not what I'm seeing. The parent kernel binding is being used instead.
Here is a test that reproduces the issue:
public interface IA
{
string GetValue();
}
public class A : IA
{
private IB _b;
public A(IB b)
{
_b = b;
}
public string GetValue()
{
return _b.Value;
}
}
public interface IB
{
string Value { get; set; }
}
public class B : IB
{
public string Value { get; set; }
}
public class TestRepro
{
[TestMethod]
public void Should_not_use_Parents_Bindings()
{
var parentKernel = new StandardKernel();
parentKernel.Bind<IA>().To<A>();
parentKernel.Bind<IB>().To<B>();
var childKernel = new ChildKernel(parentKernel);
var otherB = new B() { Value = "newValue" };
childKernel.Bind<IB>().ToConstant(otherB);
childKernel.Get<IB>().Value.ShouldEqual(otherB.Value);
childKernel.Get<IA>().GetValue().ShouldEqual(otherB.Value);
// This last assertion fails. The value returned by IA.GetValue() is null
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels