public void TestNamedParentIntrospection() { IDIContext parentContext = ContextHelper.CreateContext(); parentContext.m().Bind <IApple>(() => new Apple(), BindingName.ForType <Apple>()); IDIContext context = parentContext.Reproduce(); context.m().Bind <IApple>(() => new BigApple(), BindingName.ForType <BigApple>()); IBinding desc = context.Introspect <IApple>(BindingName.ForType <BigApple>()); Assert.IsNotNull(desc); Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType); Assert.That(desc.context == context); object apple = desc.factory(); Assert.That(apple is BigApple); desc = context.Introspect <IApple>(); Assert.IsNotNull(desc); Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType); Assert.That(desc.context == context); apple = desc.factory(); Assert.That(apple is BigApple); desc = context.Introspect <IApple>(BindingName.ForType <Apple>()); Assert.IsNotNull(desc); Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType); Assert.That(desc.context == parentContext); apple = desc.factory(); Assert.That(apple is Apple); }
public void TestNamedParentResolution() { IDIContext parentContext = ContextHelper.CreateContext(); parentContext.m().Bind <IApple>(() => new Apple(), BindingName.ForType <Apple>()); IDIContext context = parentContext.Reproduce(); context.m().Bind <IApple>(() => new BigApple(), BindingName.ForType <BigApple>()); IApple apple = context.Resolve <IApple>(BindingName.ForType <BigApple>()); Assert.That(apple is BigApple); apple = context.Resolve <IApple>(); Assert.That(apple is BigApple); apple = context.Resolve <IApple>(BindingName.ForType <Apple>()); Assert.That(apple is Apple); }