public void Resolve_InChildContainerUsesParentContainer_ReusesParentContainerAndReturnsTheReolvedObject() { var container = new NCopContainer(registry => { registry.Register <Foo>(); }); var childContainer = container.CreateChildContainer(registry => { }); var instance = childContainer.Resolve <Foo>(); Assert.IsNotNull(instance); }
public void ResolveInChildContainerAndInParentContainer_UsingAutoRegistrationInParentContainerAsSingletonReusedWithinContainer_ReturnsTheSameInstance() { var container = new NCopContainer(registry => { registry.Register <Foo>().AsSingleton().ReusedWithinHierarchy(); }); var childContainer = container.CreateChildContainer(registry => { }); var instance = container.Resolve <Foo>(); var instance2 = childContainer.Resolve <Foo>(); Assert.AreSame(instance, instance2); }
public void DisposeOfParentContainer_OfDisposableObjectWhichIsOwnedByChildContainer_ReturnsDispsoedIndication() { var parentContainer = new NCopContainer(registry => { }); var childContainer = parentContainer.CreateChildContainer(registry => { registry.Register <Foo>(); }); var instance = childContainer.Resolve <Foo>(); Assert.IsFalse(instance.IsDisposed); parentContainer.Dispose(); Assert.IsFalse(instance.IsDisposed); }
public INCopDependencyResolver CreateChildContainer() { return(container.CreateChildContainer()); }
public void DisposeOfParentContainer_OfDisposableObjectWhichIsOwnedByChildContainer_ReturnsDispsoedIndication() { var parentContainer = new NCopContainer(registry => { }); var childContainer = parentContainer.CreateChildContainer(registry => { registry.Register<Foo>(); }); var instance = childContainer.Resolve<Foo>(); Assert.IsFalse(instance.IsDisposed); parentContainer.Dispose(); Assert.IsFalse(instance.IsDisposed); }
public void ResolveInChildContainerAndInParentContainer_UsingAutoRegistrationInParentContainerAsSingletoneReusedWithinHierarchy_ReturnsNotTheSameInstance() { var container = new NCopContainer(registry => { registry.Register<Foo>().AsSingleton().WithinContainer(); }); var childContainer = container.CreateChildContainer(registry => { }); var instance1 = container.Resolve<Foo>(); var instance2 = container.Resolve<Foo>(); var instance3 = childContainer.Resolve<Foo>(); var instance4 = childContainer.Resolve<Foo>(); Assert.AreSame(instance1, instance2); Assert.AreNotSame(instance1, instance3); Assert.AreSame(instance3, instance4); }
public void ResolveInChildContainerAndInParentContainer_UsingSingletonRegistrationInParentContainer_ReturnsTheSameInstance() { var container = new NCopContainer(registry => { registry.Register<Foo>().AsSingleton().WithinHierarchy(); }); var childContainer = container.CreateChildContainer(registry => { }); var instance = container.Resolve<Foo>(); var instance2 = childContainer.Resolve<Foo>(); Assert.AreSame(instance, instance2); }
public void Resolve_InChildContainerUsesParentContainer_ReusesParentContainerAndReturnsTheReolvedObject() { var container = new NCopContainer(registry => { registry.Register<Foo>(); }); var childContainer = container.CreateChildContainer(registry => { }); var instance = childContainer.Resolve<Foo>(); Assert.IsNotNull(instance); }