In .NET core 3+ worker service we can register multiple worker services using the ConfigureServices under the CreateHostBuilder method as below
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<TestWorker1>();
services.AddHostedService<TestWorker2>();
});
Is there a way to add these services (TestWorker1,TestWorker2), based on a configuration setting (e.g. appsettings.json), So that only services that are defined in the config file are registered.
Any other generic approach's other than the config file approach are also welcome.
Thanks in advance.