Access to options in HttpClient configuration?
I'd like to configure a typed HttpClient based on options. However I don't have access to the options (or to the service provider) in the configuration delegate.
services.Configure<FooClientOptions>(Configuration.GetSection("FooClient"));
services.AddHttpClient<FooClient>(client =>
{
// Here I'd like to access FooClientOptions, but I don't have an IServiceProvider
client.BaseAddress = ...
});
How can I access the options from the configuration delegate? If it's not currently possible, it would be a useful addition.
There is an overload which passes IServiceProvider via delegate
Ah, yes, looks like it was added in 2.2.0... Is there a workaround to do this in 2.1 ?
https://github.com/aspnet/HttpClientFactory/blob/5bb701daaa087dd8dc0f0a882117e316675dda6d/src/Microsoft.Extensions.Http/DependencyInjection/HttpClientBuilderExtensions.cs#L46
Doh, how did I miss that? Thanks @dallancarr!