Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is max HTTP connections still configured using ServicePointManager.DefaultConnectionLimit?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
    });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading