Considering these topics:
https://stackoverflow.com/a/22561368/648723
https://stackoverflow.com/a/67067195/648723
https://stackoverflow.com/a/35045301/648723
They said: keep an instance of HttpClient for the lifetime of your application
But when we create a new Blazor
application, in Program.cs
file, the default HttpClient
registered as this:
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = "MyUrl"});
Why Microsoft didn't use
AddSingleton
forHttpClient
?Is it necessary to use
IHttpClientFactory
instead ofHttpClient
?If I want to use Multiple
HttpClient
in myBlazor
application, How can I register and inject intendedHttpClient
(With intended base URL) in my code?
Thanks