Exemplo n.º 1
0
        public void ScopesReturnSelfAsResolutionRoot()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var resRoot = customScope.Get <IResolutionRoot>();

            Assert.That(resRoot, Is.SameAs(customScope));
        }
Exemplo n.º 2
0
        public void ScopeServiceDifferentFromDefaultService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = _mainKernel.Get <IService>();
            var b = customScope.Get <IService>();

            Assert.That(a, Is.Not.SameAs(b));
        }
Exemplo n.º 3
0
        public void SameScopeSameService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = customScope.Get <IService>();
            var b = customScope.Get <IService>();

            Assert.That(a, Is.SameAs(b));
        }
Exemplo n.º 4
0
        public void InjectedAndResolvedChildrenGetSameService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = customScope.Get <ComplexClass>();

            Assert.That(a.InjectedServiceUser.Service,
                        Is.SameAs(a.ResolvedServiceUser.Service));
        }
Exemplo n.º 5
0
        public void DifferentExplicitScopes()
        {
            IResolutionRoot customScope1 = new CustomScope(_mainKernel);
            IResolutionRoot customScope2 = new CustomScope(_mainKernel);

            var a = customScope1.Get<IService>();
            var b = customScope2.Get<IService>();

            Assert.That(a, Is.Not.SameAs(b));
        }
Exemplo n.º 6
0
        public void DifferentExplicitScopes()
        {
            IResolutionRoot customScope1 = new CustomScope(_mainKernel);
            IResolutionRoot customScope2 = new CustomScope(_mainKernel);

            var a = customScope1.Get <IService>();
            var b = customScope2.Get <IService>();

            Assert.That(a, Is.Not.SameAs(b));
        }
Exemplo n.º 7
0
        public void CustomScopeObjectsGetGarbageCollectedWhenCustomScopeGetsGarbageCollected()
        {
            CustomScope customScope = new CustomScope(_mainKernel);

            var weakRef = new WeakReference(customScope.Get<IService>());

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Assert.That(weakRef.IsAlive, Is.True);

            customScope = null;

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Thread.Sleep(100); // required to let Ninject's cache pruning thread run.
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Assert.That(customScope, Is.Null);
            Assert.That(weakRef.IsAlive, Is.False);
        }
Exemplo n.º 8
0
        public void ChildrenGetSameServiceButDifferFromResultFromOtherKernels()
        {
            var a = _mainKernel.Get<ComplexClass>();

            Assert.That(a.InjectedServiceUser.Service,
                Is.SameAs(a.ResolvedServiceUser.Service));

            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var b = customScope.Get<ComplexClass>();

            Assert.That(b.InjectedServiceUser.Service,
                Is.SameAs(b.ResolvedServiceUser.Service));

            Assert.That(a.ResolvedServiceUser.Service,
                        Is.Not.SameAs(b.ResolvedServiceUser.Service));

            Assert.That(a.InjectedServiceUser.Service,
                Is.Not.SameAs(b.InjectedServiceUser.Service));
        }
Exemplo n.º 9
0
        public void CustomScopeObjectsGetGarbageCollectedWhenCustomScopeGetsGarbageCollected()
        {
            CustomScope customScope = new CustomScope(_mainKernel);

            var weakRef = new WeakReference(customScope.Get <IService>());

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Assert.That(weakRef.IsAlive, Is.True);

            customScope = null;

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Thread.Sleep(100); // required to let Ninject's cache pruning thread run.
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Assert.That(customScope, Is.Null);
            Assert.That(weakRef.IsAlive, Is.False);
        }
Exemplo n.º 10
0
        public void ChildrenGetSameServiceButDifferFromResultFromOtherKernels()
        {
            var a = _mainKernel.Get <ComplexClass>();

            Assert.That(a.InjectedServiceUser.Service,
                        Is.SameAs(a.ResolvedServiceUser.Service));

            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var b = customScope.Get <ComplexClass>();

            Assert.That(b.InjectedServiceUser.Service,
                        Is.SameAs(b.ResolvedServiceUser.Service));

            Assert.That(a.ResolvedServiceUser.Service,
                        Is.Not.SameAs(b.ResolvedServiceUser.Service));

            Assert.That(a.InjectedServiceUser.Service,
                        Is.Not.SameAs(b.InjectedServiceUser.Service));
        }
Exemplo n.º 11
0
        public void InjectedAndResolvedChildrenGetSameService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = customScope.Get<ComplexClass>();

            Assert.That(a.InjectedServiceUser.Service,
                Is.SameAs(a.ResolvedServiceUser.Service));
        }
Exemplo n.º 12
0
        public void ScopesReturnSelfAsResolutionRoot()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var resRoot = customScope.Get<IResolutionRoot>();

            Assert.That(resRoot, Is.SameAs(customScope));
        }
Exemplo n.º 13
0
        public void ScopeServiceDifferentFromDefaultService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = _mainKernel.Get<IService>();
            var b = customScope.Get<IService>();

            Assert.That(a, Is.Not.SameAs(b));
        }
Exemplo n.º 14
0
        public void SameScopeSameService()
        {
            IResolutionRoot customScope = new CustomScope(_mainKernel);

            var a = customScope.Get<IService>();
            var b = customScope.Get<IService>();

            Assert.That(a, Is.SameAs(b));
        }