public void GetService_UnknownService_ReturnsNull() { var container = CreateContainer(); IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container); var instance = resolver.GetService(typeof(IFoo)); Assert.IsNull(instance); }
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)); }
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()); }
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()); }
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()); } }
public void GetService_MultipleThreads_DoesNotThrowInvalidScopeException() { var container = CreateContainer(); container.Register<IFoo, Foo>(new PerScopeLifetime()); IDependencyResolver resolver = new LightInjectWebApiDependencyResolver(container); ParallelInvoker.Invoke(10, () => GetFooWithinScope(resolver)); }