Как правильно использовать HTTP-клиент в библиотеке .NET?C#

Место общения программистов C#
Ответить
Гость
 Как правильно использовать HTTP-клиент в библиотеке .NET?

Сообщение Гость »


In ASP.NET we have

Код: Выделить всё

IHttpClientFactory
which its main benefit to my understanding is that we ask the framework for HTTP client instances and the framework reuses its instances so the OS would not run out of ports.
I need to create various libraries that connect to some API, and they will be used in our ASP.NET Core backend app. But generally, it can be used on any kind of project.
My question is what is the correct way and best practice for using a HTTP client inside a library? Should I create a static one inside the project or should I ask the user of the library to provide their instance, or should I directly ask the

Код: Выделить всё

IHttpClientFactory
?
Note: this is not an opinion based question. I'm asking for the best practice and the correct one.


Источник: https://stackoverflow.com/questions/781 ... et-library
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»