I have a base class with multiple implementations and I would like to be able to register all the implementations in a look similar to Registering by Convention.
I am able to get all the implementations of the base class but when I try to actually register them I get the following exception:
System.ArgumentException: 'Open generic service type 'Bento.SearchContent.EventListener.Infrastructure.Index`1[T]' requires registering an open generic implementation type.'
public abstract class Index<T>
where T : class
{
....
}
sample subclass:
public class SurveyChangedIndex : Index<SurveyChanged>
{
....
}
sample function:
public static void RegisterIndexing()
{
var indexBase = typeof(Index<>);
GetAllDescendantsOf(Assembly.GetAssembly(indexBase), indexBase)
.ForEach(indexType => { _serviceCollection.AddSingleton(indexBase, indexType); });
_serviceCollection.AddTransient<IIndexResolver, IndexResolver>(sp => new IndexResolver(sp));
}