예제 #1
0
        public void GetService_UnknownService_ReturnsNull()
        {
            var container = CreateContainer();            
            IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);

            var instance = resolver.GetService(typeof(IFoo));
            Assert.IsNull(instance);
        }
예제 #2
0
        public void GetService_KnownService_ReturnsInstance()
        {
            var container = CreateContainer();
            container.Register<IFoo, Foo>();
            IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);

            var instance = resolver.GetService(typeof(IFoo));
            Assert.IsInstanceOfType(instance, typeof(Foo));            
        }
예제 #3
0
        public void GetServices_UnknownService_ReturnsEmptyEnumerable()
        {
            var container = CreateContainer();
            container.Register<IBar, Bar>();
            IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);

            var instances = resolver.GetServices(typeof(IFoo));

            Assert.AreEqual(0, instances.Count());
        }
예제 #4
0
        public void GetServices_MultipleServices_ReturnsAllInstances()
        {
            var container = CreateContainer();
            container.Register<IFoo, Foo>();
            container.Register<IFoo, AnotherFoo>("AnotherFoo");
            IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);

            var instances = resolver.GetServices(typeof(IFoo));
            Assert.AreEqual(2, instances.Count());
        }
예제 #5
0
 public void GetServices_MultipleServicesFromScope_ReturnsAllInstances()
 {
     var container = CreateContainer();
     container.Register<IFoo, Foo>(new PerScopeLifetime());
     container.Register<IFoo, AnotherFoo>("AnotherFoo", new PerScopeLifetime());
     IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);
     using (var scope = resolver.BeginScope())
     {
         var instances = scope.GetServices(typeof(IFoo));
         Assert.AreEqual(2, instances.Count());    
     }            
 }
예제 #6
0
 public void GetService_MultipleThreads_DoesNotThrowInvalidScopeException()
 {
      var container = CreateContainer();
     container.Register<IFoo, Foo>(new PerScopeLifetime());
     IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container);
     
     ParallelInvoker.Invoke(10, () => GetFooWithinScope(resolver));
 }