예제 #1
0
        public void ResolveGlobalInstanceWithNestedDependencies_InstancesAreTheSame()
        {
            var moreComplexDummy = new MoreComplexDummy
            {
                Name = "1234"
            };

            var complex = new ComplexDummy()
            {
                Number = 111
            };

            var dummy = new Dummy()
            {
                Number = 222
            };

            VInjector.Register <IMoreComplexDummy, MoreComplexDummy>(LifeTime.Global, moreComplexDummy);
            VInjector.Register <IComplexDummy, ComplexDummy>(LifeTime.Global, complex);
            VInjector.Register <IDummy, Dummy>(LifeTime.Global, dummy);

            var instanceResult = VInjector.Resolve <IMoreComplexDummy>();

            Assert.AreSame(moreComplexDummy, instanceResult);
            Assert.AreSame(complex, instanceResult.ComplexDummy);
            Assert.AreSame(dummy, instanceResult.ComplexDummy.Dummy);
            Assert.AreEqual("1234", instanceResult.Name);
            Assert.AreEqual(111, instanceResult.ComplexDummy.Number);
            Assert.AreEqual(222, instanceResult.ComplexDummy.Dummy.Number);
        }
예제 #2
0
        public void ResolveGlobalInstanceWithDependencies_InstancesAreTheSame()
        {
            var dummyInstance = new Dummy
            {
                Number = 111
            };

            var complex = new ComplexDummy
            {
                Number = 222
            };

            VInjector.Register <IDummy, Dummy>(LifeTime.Global, dummyInstance);
            VInjector.Register <IComplexDummy, ComplexDummy>(LifeTime.Global, complex);

            var instanceResult = VInjector.Resolve <IComplexDummy>();

            Assert.AreSame(complex, instanceResult);
            Assert.AreSame(dummyInstance, instanceResult.Dummy);
            Assert.AreEqual(111, instanceResult.Dummy.Number);
            Assert.AreEqual(222, instanceResult.Number);
        }