Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active June 8, 2018 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/b6c1c5d60ce989b4ef87c5a2e877d370 to your computer and use it in GitHub Desktop.
Save christiannagel/b6c1c5d60ce989b4ef87c5a2e877d370 to your computer and use it in GitHub Desktop.
Configuring IHttpClientFactory in the dependency injection container
public FactorySample() => 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");
});
services.AddTransient<ControllerUsingClientFactory>();
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