I have a situation where I have a method that takes a generic type
Configuration<TConfiguration>() where TConfiguration : class
and in the method we bind TConfiguration
to a generic service that handles all CRUD opperations for TConfiguration
.
Now for every class we want to use Configuration<TConfiguration>()
we have to call the registration of it. Is there a way that we can implement a interface on the classes and for every class that implements the interface call the registration of it?
Something like
var type = typeof(IClasses);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p));
foreach (var classType in types)
{
services.Register<classType>(webHostContext.Configuration);
}