WiseJ 4 and IHttpClientFactory

0
0

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

  • You must to post comments
0
0

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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.