示例#1
0
        public void DisposeOfContainer_OfDisposableObjectWhichIsOwnedExternally_ReturnsNotDispsoedIndication()
        {
            var container = new NCopContainer(registry => {
                registry.Register <Foo>().OwnedExternally();
            });

            var instance = container.Resolve <Foo>();

            Assert.IsFalse(instance.IsDisposed);
            container.Dispose();
            Assert.IsFalse(instance.IsDisposed);
        }
示例#2
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);
        }
示例#3
0
        public void DisposeOfContainer_OfDisposableNamedObjectWithAnArgumentWhichIsOwnedExternally_ReturnsTheNamedInstanceWithNotDispsoedIndication()
        {
            var container = new NCopContainer(registry => {
                registry.Register <IFoo, string>((c, name) => new Foo(name))
                .Named("NCop")
                .OwnedExternally();
            });

            var instance = container.TryResolve <string, IFoo>("NCop", "NCop") as Foo;

            container.Dispose();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance.Name.Equals("NCop"));
            Assert.IsFalse(instance.IsDisposed);
        }
 public void Dispose()
 {
     container.Dispose();
 }
示例#5
0
        public void DisposeOfContainer_OfDisposableNamedObjectWithAnArgumentWhichIsOwnedExternally_ReturnsTheNamedInstanceWithNotDispsoedIndication() {
            var container = new NCopContainer(registry => {
                registry.Register<IFoo, string>((c, name) => new Foo(name))
                        .Named("NCop")
                        .OwnedExternally();
            });

            var instance = container.TryResolve<string, IFoo>("NCop", "NCop") as Foo;

            container.Dispose();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance.Name.Equals("NCop"));
            Assert.IsFalse(instance.IsDisposed);
        }
示例#6
0
        public void DisposeOfContainer_OfDisposableObjectWhichIsOwnedExternally_ReturnsNotDispsoedIndication() {
            var container = new NCopContainer(registry => {
                registry.Register<Foo>().OwnedExternally();
            });

            var instance = container.Resolve<Foo>();

            Assert.IsFalse(instance.IsDisposed);
            container.Dispose();
            Assert.IsFalse(instance.IsDisposed);
        }
示例#7
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);
        }