using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
public static IConfiguration Configuration
public static async Task Main()
Configuration = new ConfigurationBuilder().Build();
var collection = new ServiceCollection();
collection.AddSingleton<IConfiguration>(Configuration);
.AddHttpClient("TenantsService")
.AddTypedClient<ITenantProvider>(c =>
new TenantProvider(new TenantProviderSettings
BaseUrl = new Uri("https://the-uri-you-need.com")
var tempServiceProvider = collection.BuildServiceProvider();
var tenantsToRegister = await tempServiceProvider.GetRequiredService<ITenantProvider>().GetAsync();
foreach (var tenant in tenantsToRegister)
collection.AddScoped<IGraphQLServer, GraphQLServer>();
using (var scope = collection.BuildServiceProvider().CreateScope())
var sp = scope.ServiceProvider;
var servers = sp.GetServices<IGraphQLServer>();
Console.WriteLine("Registered servers: {0}", servers.Count());
public interface ITenantProvider
Task<IEnumerable<string>> GetAsync();
public class TenantProvider : ITenantProvider
public TenantProvider(TenantProviderSettings settings, System.Net.Http.HttpClient client)
public Task<IEnumerable<string>> GetAsync()
return Task.FromResult<IEnumerable<string>>(
public class TenantProviderSettings
public interface IGraphQLServer
public class GraphQLServer : IGraphQLServer