Hi,
is it possible to use AddHttpClient() extension (or similad) so I can inject IHttpClientFactory and then, in my client, I can instantiate an HttpClient with _httpClient = httpClientFactory.CreateClient(); ?
Thanks,
Luca
Hi Luca,
You can use the AddHttpClient() extension method to add the HttpClient to your service container, but in order to use it you’ll need to use Microsoft’s IServiceProvider.
The code in startup.cs should look like this:
// ASP.NET Core startup
public class Startup {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
WebRootPath = “./”
});
builder.Services.AddHttpClient();
var app = builder.Build();
// Register Microsoft’s IServiceProvider with Wisej.NET.
Application.Services.AddService<IServiceProvider>(app.Services);
app.UseWisej();
app.UseFileServer();
app.Run();
}
}
Then you can use it as you would normally would, i.e calling httpClientFactory.CreateClient();
HTH,
Alaa
Please login first to submit.