using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddScoped<IValidator<object, Cat>, MyClass<object, Cat>>();
services.AddScoped<IValidator<object, Dog>, MyClass<object, Dog>>();
services.AddScoped<IValidator<Cat, Dog>, MyClass<Cat, Dog>>();
var sp = services.BuildServiceProvider();
using (var scope = sp.CreateScope())
var validators = scope.ServiceProvider.GetService<IEnumerable<IValidator<object, Cat>>>();
public interface IValidator<in TModel, in TContext>;
class MyClass<TModel, TContext> : IValidator<TModel, TContext>
Console.WriteLine($"MyClass: {typeof(TModel)} - {typeof(TContext)}");