I need to make a series of HTTP calls to obtain database credentials from a 3rd party vault, given that I need to run this code in Program.cs or, at the very latest, Startup.cs before adding the DBContext, I need to be able to make these calls without using IHttpClientFactory, as that requires Dependency Injection to already have been initialized.
The following code works fine when called during runtime, but doesn't work during the ConfigureAppConfiguration step.
HttpClient client = _clientFactory.CreateClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"{_configuration["CredentialsVault:vaultUrl"]}Auth/SignAppIn");
request.Headers.Add("Authorization", $"PS-Auth key={_apiKey}; runas={_runAsUser};");
var response = await client.SendAsync(request);
Is there a way I can either make an HTTP call without having to rely on Dependency Injection, or delay AddDbContext until after Dependency Injection has been set up?
I have tried creating an instance of HttpClient like this:
HttpClient client = new HttpClient();
However this did not seem to work, and according to this question it should not be instantiated like that.