示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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());
 }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }