I want to use a typed HTTP client so I register it like this in the ServiceCollection
services.AddHttpClient<ApiService>();
All the requests that the client makes, must be authenticated. So I'd need to slightly modify the snippet above to this:
services.AddHttpClient<ApiService>(c =>
{
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "");
});
The bearer token needs to be renewed all 5 minutes, so I need to create service that needs dependencies like an HttpClient (to authenticate and get the token) and a MemoryCache (to store the token as long it's valid).
The problem is, as you can see, this is still in the phase before the service provider is built, so I can't resolve anything at this point... What are my options here?