-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...nt_type_parameter_fails_with_RegisteringImplementationNotAssignableToServiceType_error.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IValidator<ExtraSettings>, 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<in T> | ||
{ | ||
public bool IsValid(T settings); | ||
} | ||
|
||
public abstract class AbstractValidator<T> : IValidator<T> | ||
{ | ||
public bool IsValid(T settings) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public class SettingsValidator : AbstractValidator<Settings> | ||
{ | ||
|
||
} | ||
|
||
} | ||
} |