示例#1
0
        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);
        }
示例#2
0
        public void TestMPSubjective()
        {
            IDIContext context = ContextHelper.CreateContext();

            context.m().Bind <IOrange> (() => new Orange1());
            context.m().Bind <IApple> (() => new Apple());
            IDIContext childContext = context.Reproduce();

            childContext.m().Bind <IOrange> (() => new Orange2());

            IApple apple2 = childContext.Resolve <IApple> ();
            IApple apple1 = context.Resolve <IApple> ();

            Assert.AreNotSame(apple1, apple2);
            Assert.IsInstanceOf(typeof(Orange1), apple1.orange);
            Assert.IsInstanceOf(typeof(Orange2), apple2.orange);
        }
示例#3
0
        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);
        }