Esempio n. 1
0
        public void ShouldCallConfigureAction()
        {
            bool wasCalled = false;
            var  factory   = new LightInjectServiceProviderFactory(o => wasCalled = true);

            Assert.True(wasCalled);
        }
        public void ShouldCreateServiceProvider()
        {
            var serviceCollection = new ServiceCollection();
            var factory           = new LightInjectServiceProviderFactory();
            var container         = factory.CreateBuilder(serviceCollection);
            var provider          = factory.CreateServiceProvider(container);

            Assert.IsAssignableFrom <IServiceContainer>(container);
        }
        public void ShouldUseExistingContainer()
        {
            var serviceCollection = new ServiceCollection();
            var container         = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings());
            var factory           = new LightInjectServiceProviderFactory(container);
            var builder           = factory.CreateBuilder(serviceCollection);

            Assert.Same(container, builder);
        }
        public void ShouldCallConfigureAction()
        {
            bool wasCalled = false;
            var  factory   = new LightInjectServiceProviderFactory(o => wasCalled = true);

            Assert.True(wasCalled);
            var container = factory.CreateBuilder(new ServiceCollection());

            Assert.IsType <ServiceContainer>(container);
        }
        public void ShouldPickServiceWithoutServiceNameAsDefaultIfRegistered()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <string>(p => "42");
            var factory   = new LightInjectServiceProviderFactory();
            var container = factory.CreateBuilder(serviceCollection);

            container.Register <string>(f => "84");
            var provider = container.CreateServiceProvider(serviceCollection);
            var value    = provider.GetService <string>();

            Assert.Equal("84", value);
        }
        public void ShouldDisposePerContainerServicesWhenProviderIsDisposed()
        {
            var serviceCollection = new ServiceCollection();
            var factory           = new LightInjectServiceProviderFactory();
            var container         = factory.CreateBuilder(serviceCollection);

            container.Register <DisposableFoo>(new PerContainerLifetime());
            using (var provider = (IDisposable)container.CreateServiceProvider(serviceCollection))
            {
                ((IServiceProvider)provider).GetService <DisposableFoo>();
            }

            Assert.True(DisposableFoo.IsDisposed);
        }
        public void ShouldDisposeRootScopeWhenProviderIsDisposed()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <DisposableFoo>();
            var factory   = new LightInjectServiceProviderFactory();
            var container = factory.CreateBuilder(serviceCollection);
            var provider  = factory.CreateServiceProvider(container);

            var foo = provider.GetService <DisposableFoo>();

            ((IDisposable)provider).Dispose();

            Assert.True(foo.IsDisposed);
        }
        public void ShouldDisposeRootScopeWhenProviderRequestedFromContainerIsDisposed()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <DisposableFoo>();

            var factory           = new LightInjectServiceProviderFactory(new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings()));
            var container         = factory.CreateBuilder(serviceCollection);
            var provider          = factory.CreateServiceProvider(container);
            var requestedProvider = provider.GetService <IServiceProvider>();

            var foo = provider.GetService <DisposableFoo>();

            ((IDisposable)requestedProvider).Dispose();

            Assert.True(foo.IsDisposed);
        }
 public void ShouldCreateBuilder()
 {
     var serviceCollection = new ServiceCollection();
     var factory           = new LightInjectServiceProviderFactory();
     var container         = factory.CreateBuilder(serviceCollection);
 }