diff --git a/test/DryIoc.Microsoft.DependencyInjection.Specification.Tests/GHIssue432_Resolving_interfaces_with_contravariant_type_parameter_fails_with_RegisteringImplementationNotAssignableToServiceType_error.cs b/test/DryIoc.Microsoft.DependencyInjection.Specification.Tests/GHIssue432_Resolving_interfaces_with_contravariant_type_parameter_fails_with_RegisteringImplementationNotAssignableToServiceType_error.cs new file mode 100644 index 00000000..e808d188 --- /dev/null +++ b/test/DryIoc.Microsoft.DependencyInjection.Specification.Tests/GHIssue432_Resolving_interfaces_with_contravariant_type_parameter_fails_with_RegisteringImplementationNotAssignableToServiceType_error.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Microsoft.Extensions.DependencyInjection; + +namespace DryIoc.Microsoft.DependencyInjection.Specification.Tests +{ + [TestFixture] + public class GHIssue432_Resolving_interfaces_with_contravariant_type_parameter_fails_with_RegisteringImplementationNotAssignableToServiceType_error + { + [Test] + public void Test1() + { + var type = typeof(IValidator<>).MakeGenericType(typeof(ExtraSettings)); + var services = new ServiceCollection(); // Microsoft.Extensions.DependencyInjection + + services.AddSingleton, SettingsValidator>(); + + var container = new Container(); + var adaptedContainer = container.WithDependencyInjectionAdapter(services); // this throws + IServiceProvider serviceProvider = adaptedContainer; + + var validator = serviceProvider.GetService(type); + Assert.NotNull(validator); + } + + public class Settings + { + public string Address { get; set; } + } + + public class ExtraSettings : Settings + { + public string Key { get; set; } + } + + public interface IValidator + { + public bool IsValid(T settings); + } + + public abstract class AbstractValidator : IValidator + { + public bool IsValid(T settings) + { + return true; + } + } + + public class SettingsValidator : AbstractValidator + { + + } + + } +}