public void ShouldCreateOnlyOneExplicitNonDisposable()
        {
            // note - this works because we pass the same target both times
            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);

                var result2 = scope.ActivateExplicit(
                    new ResolveContext(scope, typeof(NoCtor)),
                    target.Id,
                    factory);

                Assert.Same(result, result2);
            }
        }
        public void ShouldDisposeExplicitIDisposable()
        {
            Disposable disposable;

            using (var scope = new DisposingContainerScope(new Container()))
            {
                disposable = scope.ActivateExplicit(
                    new ResolveContext(scope, typeof(Disposable)),
                    new TestTarget().Id,
                    c => new Disposable());
            }

            Assert.True(disposable.Disposed);
            Assert.Equal(1, disposable.DisposedCount);
        }
        public void ImplicitlyScopedObjectShouldNotBeSameAsExplicitlyScopedObject()
        {
            Disposable explicitlyScoped, implicitlyScoped;

            using (var scope = new DisposingContainerScope(new Container()))
            {
                Func <ResolveContext, Disposable> factory = c => new Disposable();
                explicitlyScoped = scope.ActivateExplicit(
                    new ResolveContext(scope, typeof(Disposable)),
                    new TestTarget().Id,
                    factory);

                implicitlyScoped = scope.ActivateImplicit(
                    new Disposable());

                Assert.NotSame(explicitlyScoped, implicitlyScoped);
            }
            Assert.True(explicitlyScoped.Disposed);
            Assert.True(implicitlyScoped.Disposed);
        }
        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);
                }
            }
        }