コード例 #1
0
        public void WhenDisposingParentChildDisposes()
        {
            UnityContainer  parent = new UnityContainer();
            IUnityContainer child  = parent.CreateChildContainer();

            TestContainer3 obj = new TestContainer3();

            child.RegisterInstance <TestContainer3>(obj);

            parent.Dispose();
            Assert.IsTrue(obj.WasDisposed);
        }
コード例 #2
0
        public void ParentNotDisposedWhenChildDisposed()
        {
            UnityContainer  parent = new UnityContainer();
            IUnityContainer child  = parent.CreateChildContainer();
            TestContainer   obj1   = new TestContainer();
            TestContainer3  obj3   = new TestContainer3();

            parent.RegisterInstance <TestContainer>(obj1);
            child.RegisterInstance <TestContainer3>(obj3);

            child.Dispose();
            //parent not getting disposed
            Assert.IsFalse(obj1.WasDisposed);

            //child getting disposed.
            Assert.IsTrue(obj3.WasDisposed);
        }
コード例 #3
0
        public void ChildInheritsParentsConfiguration_RegisterInstanceResolveAll()
        {
            ITestContainer objdefault = new TestContainer();
            ITestContainer objfirst   = new TestContainer1();
            ITestContainer objsecond  = new TestContainer2();
            ITestContainer objthird   = new TestContainer3();
            UnityContainer parent     = new UnityContainer();

            parent.RegisterInstance <ITestContainer>(objdefault)
            .RegisterInstance <ITestContainer>("first", objfirst)
            .RegisterInstance <ITestContainer>("second", objsecond);

            IUnityContainer child = parent.CreateChildContainer()
                                    .RegisterInstance <ITestContainer>("third", objthird);

            List <ITestContainer> list = new List <ITestContainer>(child.ResolveAll <ITestContainer>());

            Assert.AreEqual(3, list.Count);
        }
コード例 #4
0
        public void ParentNotDisposedWhenChildDisposed()
        {
            UnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();
            TestContainer obj1 = new TestContainer();
            TestContainer3 obj3 = new TestContainer3();
            parent.RegisterInstance<TestContainer>(obj1);
            child.RegisterInstance<TestContainer3>(obj3);

            child.Dispose();
            //parent not getting disposed
            Assert.IsFalse(obj1.WasDisposed);

            //child getting disposed.
            Assert.IsTrue(obj3.WasDisposed);
        }
コード例 #5
0
        public void WhenDisposingParentChildDisposes()
        {
            UnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();

            TestContainer3 obj = new TestContainer3();
            child.RegisterInstance<TestContainer3>(obj);

            parent.Dispose();
            Assert.IsTrue(obj.WasDisposed);
        }
コード例 #6
0
        public void ChildInheritsParentsConfiguration_RegisterInstanceResolveAll()
        {
            ITestContainer objdefault = new TestContainer();
            ITestContainer objfirst = new TestContainer1();
            ITestContainer objsecond = new TestContainer2();
            ITestContainer objthird = new TestContainer3();
            UnityContainer parent = new UnityContainer();
            
            parent.RegisterInstance<ITestContainer>(objdefault)
                .RegisterInstance<ITestContainer>("first", objfirst)
                .RegisterInstance<ITestContainer>("second", objsecond);

            IUnityContainer child = parent.CreateChildContainer()
                .RegisterInstance<ITestContainer>("third", objthird);

            List<ITestContainer> list = new List<ITestContainer>(child.ResolveAll<ITestContainer>());
            
            Assert.AreEqual(3, list.Count);
        }