public interface IApiClient
{
...
}
public class ApiClient : IApiClient
{
private readonly HttpClient client;
public ApiClient(HttpClient client) => this.client = client;
... things that interact with client ...
}
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddHttpClient<IApiClient, ApiClient>();
...
}
...
}
For example what if you need to add a base address to the client?
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddHttpClient<IApiClient, ApiClient>(client =>
{
client.BaseAddress = new Uri("<<the url for the api>>");
});
...
}
...
}