Given the following classes:
public class HttpHelper
{
private readonly HttpClient client;
public HttpHelper(HttpClient client)
{
this.client = client;
}
}
public class ServiceA
{
private readonly HttpHelper helper;
public ServiceA(HttpHelper helper)
{
this.helper = helper;
}
}
public class ServiceB
{
private readonly HttpHelper helper;
public ServiceB(HttpHelper helper)
{
this.helper = helper;
}
}
and the following setup:
sc.AddSingleton<ServiceA>()
.AddHttpClient<HttpHelper>()
.ConfigureHttpClient((sp, client) => { client.BaseAddress = new Uri("http://domainA"); });
sc.AddSingleton<ServiceB>()
.AddHttpClient<HttpHelper>()
.ConfigureHttpClient((sp, client) => { client.BaseAddress = new Uri("http://domainB"); });
When I try to resolve ServiceA and ServiceB they both get an HttpClient with the same URL.
How do I change the registration in DI, so that each services get the correct HttpClient injected?
TIA
/Søren