Skip to content

Instantly share code, notes, and snippets.

@lawrence-laz
Last active January 26, 2021 19:55
Show Gist options
  • Save lawrence-laz/a934876e95dfb993a43365b0fa286372 to your computer and use it in GitHub Desktop.
Save lawrence-laz/a934876e95dfb993a43365b0fa286372 to your computer and use it in GitHub Desktop.
Add HttpMessageHandler to all HttpClients
services.AddSingleton<IConfigureOptions<HttpClientFactoryOptions>>(provider =>
{
return new ConfigureNamedOptions<HttpClientFactoryOptions>(name: null, options =>
{
options.HttpMessageHandlerBuilderActions.Add(builder =>
{
builder.AdditionalHandlers.Add(provider.GetRequiredService<YourHandler>());
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment