public void Resolve_single_service_with_multiple_registrations_should_resolve_the_same_way_as_microsoft_di(
            bool usingScope, ServiceLifetime firstLifetime, ServiceLifetime secondLifetime, Type expectedResolveType)
        {
            // arrange
            var collection = new ServiceCollection();

            collection.Add(ServiceDescriptor.Describe(typeof(IService), typeof(ServiceA), firstLifetime));
            collection.Add(ServiceDescriptor.Describe(typeof(IService), typeof(ServiceB), secondLifetime));

            IServiceProvider msProvider     = collection.BuildServiceProvider();
            IServiceProvider dryiocProvider = DryIocAdapter.Create(collection);

            if (usingScope)
            {
                msProvider     = msProvider.CreateScope().ServiceProvider;
                dryiocProvider = dryiocProvider.CreateScope().ServiceProvider;
            }

            // act
            var msService     = msProvider.GetRequiredService <IService>();
            var dryiocService = dryiocProvider.GetRequiredService <IService>();

            // assert
            Assert.IsInstanceOf(expectedResolveType, msService, "Microsoft changed the implementation");
            Assert.IsInstanceOf(expectedResolveType, dryiocService, "DryIoc resolves the requested type different than microsofts di implementation");
        }
예제 #2
0
 protected override IServiceProvider CreateServiceProvider(IServiceCollection services) => DryIocAdapter.Create(services);
예제 #3
0
 /// <summary>Creates **new** container configured for Microsoft.Extensions.DependencyInjection
 /// with user provided configuration or by default.</summary>
 public IContainer CreateBuilder(IServiceCollection services) =>
 _configureContainer?.Invoke(services) ?? DryIocAdapter.Create(services);