public void RequestScopeAvailableWhenRequestRunning()
        {
            var kernel      = CreateKernel(new ServiceCollection());
            var contextMock = new Mock <IContext>();

            using (var aspNetScope = new NinjectServiceScope(kernel))
            {
                var requestScope = kernel.Components.GetAll <INinjectHttpApplicationPlugin>().Select(c => c.GetRequestScope(contextMock.Object)).FirstOrDefault(s => s != null);
                requestScope.Should().NotBeNull().And.BeOfType(typeof(RequestScope));
            }
        }
Ejemplo n.º 2
0
        public void ScopedRegistrationIsConvertedToInRequestScope()
        {
            var collection = new ServiceCollection();

            collection.Add(new ServiceDescriptor(typeof(IWarrior), typeof(Samurai), ServiceLifetime.Scoped));

            var kernel = CreateKernel(collection);

            IWarrior first;

            using (var scope1 = new NinjectServiceScope(kernel))
            {
                first = kernel.Get <IWarrior>();
                var second = kernel.Get <IWarrior>();
                first.Should().BeSameAs(second).And.BeOfType(typeof(Samurai));
            }
            using (var scope2 = new NinjectServiceScope(kernel))
            {
                var third = kernel.Get <IWarrior>();
                third.Should().NotBeSameAs(first).And.BeOfType(typeof(Samurai));
            }
        }