I have a multitenant application on a micro service architecture design.
I want to inject X number of services, depending on the number of tenants running.
public void ConfigureServices(IServiceCollection services)
{
// ... OTHER DI
services.AddHttpClient("TenantsService")
.AddTypedClient<ITenantServiceClient>(c => new TenantServiceClient(new TenantServiceClientSettings()
{
AccessKey = Configuration["TenantsService:ApiKey"],
BaseUrl = new Uri(Configuration["TenantsService:Url"])
}, c));
foreach (var tenant in TenantsToRegister)
{
services
.AddGraphQLServer($"{tenant.Name}");
}
...
}
The above code would work if I had the list of tenants when the application starts. But I need to request that list from another microservice. Having this constraint, I need to build the service provider in order to get that list. At the same time, I need the list before the service provider's build to inject the services I need.
The only option that I see is adding the services at runtime, but I'm not sure if it's possible.