Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Configuring a typed HttpClient in the dependency injection container
public TypedClientSample() => AppServices = ConfigureServices();
private ServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
services.AddLogging(builder =>
{
builder.AddFilter((category, level) => true);
builder.AddConsole(options => options.IncludeScopes = true);
});
services.AddHttpClient("cni", client =>
{
client.BaseAddress = new Uri("https://www.cninnovation.com");
}).AddTypedClient<TypedClient>();
return services.BuildServiceProvider();
}
public IServiceProvider AppServices { get; private set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment