public void WhenDisposingParentChildDisposes() { IUnityContainer parent = new UnityContainer(); IUnityContainer child = parent.CreateChildContainer(); TestContainer3 obj = new TestContainer3(); child.RegisterInstance <TestContainer3>(obj); parent.Dispose(); Assert.IsTrue(obj.WasDisposed); }
public void ParentNotDisposedWhenChildDisposed() { IUnityContainer 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); }
public void ChildInheritsParentsConfiguration_RegisterInstanceResolveAll() { ITestContainer objdefault = new TestContainer(); ITestContainer objfirst = new TestContainer1(); ITestContainer objsecond = new TestContainer2(); ITestContainer objthird = new TestContainer3(); IUnityContainer 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); }