public void DisposingParentDisposesChild() { var parent = GetContainer(); var child = parent.CreateChildContainer(); MyDisposableObject spy = new MyDisposableObject(); child.RegisterInstance(spy); parent.Dispose(); Assert.IsTrue(spy.WasDisposed); }
public void CanDisposeChildWithoutDisposingParent() { MyDisposableObject parentSpy = new MyDisposableObject(); MyDisposableObject childSpy = new MyDisposableObject(); var parent = GetContainer(); parent.RegisterInstance(parentSpy); var child = parent.CreateChildContainer() .RegisterInstance(childSpy); child.Dispose(); Assert.IsFalse(parentSpy.WasDisposed); Assert.IsTrue(childSpy.WasDisposed); childSpy.WasDisposed = false; parent.Dispose(); Assert.IsTrue(parentSpy.WasDisposed); Assert.IsFalse(childSpy.WasDisposed); }