The answer from @maxim helped me. I ended up creating this extension class to load all services derived from the base class ProcessorBase
automatically. Sharing in case it helps
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddJobProcessors(this IServiceCollection services, Assembly assembly = null)
{
assembly ??= Assembly.GetCallingAssembly();
var processorTypes = assembly.GetTypes()
.Where(t => t.IsClass
&& !t.IsAbstract
&& t.BaseType != null
&& t.BaseType.IsGenericType
&& t.BaseType.GetGenericTypeDefinition() == typeof(ProcessorBase<>));
foreach (var processor in processorTypes)
services.AddTransient(typeof(IHostedService), processor);
return services;
}
}
Usage:
services.AddJobProcessors();