I'm trying to register a Typed HttpClient in my ASP.NET 2.1 Web Application where the Typed HttpClient requires an API Key, defined in the constructor.
e.g.
Startup.cs
----------
services.AddHttpClient<MyHttpClient>();
MyHttpClient.cs
---------------
public class MyHttpClient(string apiKey, HttpClient httpClient) { .. }
As you can see, I'm pretty sure the IoC/DI wouldn't know how to create the instance of the MyHttpClient because it wouldn't know what value to inject into the string apiKey parameter.
Is this possible?
I've also tried referencing the Microsoft docs about "Fundamentals - Http Requests (Typed Clients)" but couldn't see any examples of this.
apiKeyinstead beIApiKeyProvider? Then buildApiKeyProviderwhich provides theapiKey.services.AddHttpClient<MyHttpClient>(c => { c.DefaultRequestHeaders.Add("Authorization", "{apikey}"); });MyHttpClientactually derive fromHttpClientor is it a wrapper?