In creating a bot that queries a web API recently, I noticed that it still seems to be the case that if you want to limit concurrent connections by the HTTP client, you have to set a centralized property DefaultConnectionLimit on ServicePointManager. Isn’t this a very outdated way to configure things given .NET’s DI system these days? Why isn’t there an option to set a connection limit on an individual HttpClient (maybe you want different HTTP clients to have different limits)? Is it just because of some legacy implementation or is there a technical justification for the centralized connection limit configuration?
>Solution :
If I understand your question correctly you can achieve this by configuring HttpMessageHandler. For example something like the following:
builder.Services.AddHttpClient<SomeHttpClient>()
.ConfigurePrimaryHttpMessageHandler(x => new HttpClientHandler
{
MaxConnectionsPerServer = 100
});