示例#1
0
        public void WhenInstanceIsRegisteredAsSingletonEnsureItIsNotGarbageCollected()
        {
            ITest iTest;
            BTest objB = new BTest();

            UnityContainer uc1 = new UnityContainer();

            uc1.RegisterType <ITest, ATest>("ATest");
            iTest = objB;

            uc1.RegisterInstance <ITest>("BTest", iTest);

            iTest = (ITest)uc1.Resolve(typeof(ITest), "BTest");
            Assert.IsNotNull(iTest);

            iTest = null;

            GC.Collect();

            iTest = (ITest)uc1.Resolve(typeof(ITest), "BTest");

            Assert.IsNotNull(iTest);

            iTest = (ITest)uc1.Resolve(typeof(ITest), "ATest");

            Assert.IsNotNull(iTest);
        }
示例#2
0
        public void WhenInstanceIsRegisteredAsSingletonEnsureItIsNotGarbageCollected()
        {
            ITest iTest;
            BTest objB = new BTest();

            UnityContainer uc1 = new UnityContainer();

            uc1.RegisterType<ITest, ATest>("ATest");
            iTest = objB;

            uc1.RegisterInstance<ITest>("BTest", iTest);

            iTest = (ITest)uc1.Resolve(typeof(ITest), "BTest");
            Assert.IsNotNull(iTest);

            iTest = null;

            GC.Collect();

            iTest = (ITest)uc1.Resolve(typeof(ITest), "BTest");
            
            Assert.IsNotNull(iTest);

            iTest = (ITest)uc1.Resolve(typeof(ITest), "ATest");

            Assert.IsNotNull(iTest);
        }
示例#3
0
        public void ResolveAllOnlyReturnsInterfaceRegistrations()
        {
            ITest iTest;

            ATest objA = new ATest();
            BTest objB = new BTest();
            CTest objC = new CTest();

            objA.Strtest = "Hi";

            UnityContainer uc1 = new UnityContainer();

            uc1.RegisterType <ITest, ATest>();

            iTest = objA;
            uc1.RegisterInstance("ATest", iTest);
            iTest = objB;
            uc1.RegisterInstance("BTest", iTest);
            iTest = objC;
            uc1.RegisterInstance("CTest", iTest);

            List <ATest> list  = new List <ATest>(uc1.ResolveAll <ATest>());
            List <ITest> list3 = new List <ITest>(uc1.ResolveAll <ITest>());

            Assert.AreEqual(0, list.Count);
            Assert.AreEqual(3, list3.Count);
        }
示例#4
0
        public void ResolveAllOnlyReturnsInterfaceRegistrations()
        {
            ITest iTest;

            ATest objA = new ATest();
            BTest objB = new BTest();
            CTest objC = new CTest();

            objA.Strtest = "Hi";

            UnityContainer uc1 = new UnityContainer();

            uc1.RegisterType<ITest, ATest>();

            iTest = objA;
            uc1.RegisterInstance("ATest", iTest);
            iTest = objB;
            uc1.RegisterInstance("BTest", iTest);
            iTest = objC;
            uc1.RegisterInstance("CTest", iTest);

            List<ATest> list = new List<ATest>(uc1.ResolveAll<ATest>());
            List<ITest> list3 = new List<ITest>(uc1.ResolveAll<ITest>());

            Assert.AreEqual(0, list.Count);
            Assert.AreEqual(3, list3.Count);
        }