using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
public static async Task Main()
var services = new ServiceCollection();
services.AddHttpClient<IMyClass, MyClass>(i =>
i.BaseAddress = new Uri("https://google.com");
Console.WriteLine("I was here!");
var service = services.BuildServiceProvider().GetRequiredService<IMyClass>();
await service.DownloadAsync();
public class MyClass : IMyClass
private HttpClient _client;
public MyClass(HttpClient client)
public async Task DownloadAsync()
var results = await _client.GetAsync("/");
Console.WriteLine("I downloaded something!");
public interface IMyClass