I have a type IReadableEntity<T>
which is generic and needs a T
type to be specified when we want to implement it.
Using dependency injection, I'm trying to get all the implementation of it :
using (var scope = app.Services.CreateScope())
{
var test = scope.ServiceProvider.GetService(typeof(IEnumerable<>).MakeGenericType(typeof(IReadableEntity<>)));
}
Usually, I can get all the implementation of an interface as a list by using this pattern, but it does not work with an open generic type. I get the following error :
System.NotSupportedException : 'Cannot create arrays of open type.'
How can I get all the implementation of my interface IReadableEntity<T>
regardless of the type of T
?