public void ParentScopeShouldDisposeAllChildScopesAndObjects() { Disposable parentObj, childObj, grandChildObj, siblingObj; using (var parent = new DisposingContainerScope(new Container())) { var child = parent.CreateScope(); var grandChild = child.CreateScope(); var sibling = parent.CreateScope(); parentObj = parent.ActivateImplicit(new Disposable()); childObj = child.ActivateImplicit(new Disposable()); grandChildObj = grandChild.ActivateImplicit(new Disposable()); siblingObj = sibling.ActivateImplicit(new Disposable()); } Assert.All(new[] { parentObj, childObj, grandChildObj, siblingObj }, d => { Assert.True(d.Disposed); Assert.Equal(1, d.DisposedCount); }); }
public void ChildScopeShouldDisposeItsOwnImplicitDisposable() { using (var scope = new DisposingContainerScope(new Container())) { Disposable inner1, inner2; using (var childScope = scope.CreateScope()) { inner1 = childScope.ActivateImplicit(new Disposable()); } Assert.True(inner1.Disposed); Assert.Equal(1, inner1.DisposedCount); using (var childScope = scope.CreateScope()) { inner2 = childScope.ActivateImplicit(new Disposable()); } Assert.True(inner2.Disposed); Assert.Equal(1, inner2.DisposedCount); } }
public void ChildScopeShouldGetItsOwnExplicitInstance() { using (var scope = new DisposingContainerScope(new Container())) { Func <ResolveContext, NoCtor> factory = c => new NoCtor(); var target = new TestTarget(); var result = scope.ActivateExplicit( new ResolveContext(scope, typeof(NoCtor)), target.Id, factory); Assert.NotNull(result); using (var childScope = scope.CreateScope()) { var result2 = childScope.ActivateExplicit( new ResolveContext(childScope, typeof(NoCtor)), target.Id, factory); Assert.NotSame(result, result2); } } }