Ejemplo n.º 1
0
        private void ConfigureResolver(HttpConfiguration config, IAppBuilder app)
        {
            var resolver = new NinjectResolver(new SingletonServiceRegistrations());

            resolver.AddRequestScopedModules(new ScopedServiceRegistration());
            if (app.IsTestingEnvironment())
            {
                resolver.AddRequestScopedModules(new DbContextRegistration());
            }
            config.DependencyResolver = resolver;
        }
Ejemplo n.º 2
0
        public void CanResolve_RequestScopedDependency()
        {
            //arrange
            var depResolver = new NinjectResolver();

            depResolver.AddRequestScopedModules(new FakeNinjectModule());
            //assert
            Assert.That(depResolver.BeginScope().GetService(typeof(IFakeService)), Is.TypeOf <FakeService>());
        }
Ejemplo n.º 3
0
        public void GivenScopedConfiguration_WhenCallingBeginScope_EachTimeShouldReturnNewInstance()
        {
            //arrange
            var depResolver = new NinjectResolver();

            depResolver.AddRequestScopedModules(new FakeNinjectModule());

            //act
            var instance1 = depResolver.BeginScope().GetService(typeof(IFakeService));
            var instance2 = depResolver.BeginScope().GetService(typeof(IFakeService));

            Assert.That(instance1, Is.Not.EqualTo(instance2));
        }