如何将HTTPCLIENT与第三方LIB一起使用?

发布于 2025-01-22 19:31:11 字数 693 浏览 1 评论 0原文

示例初始情况:

可以说我有一个带有依赖注入的Web API。 我通常会将一个httpclient绑定为单身人士。

我认为httpclient被认为主要是线程安全。
https://codereview.stackexchange.com/questions/questions/questions/questions/6999950/single-instance/single-instance/single-instance/single-instance/single-instance/single-instance/single-instance/可重复使用的httpclient
(最佳答案 - 三个链接),

但是有些成员不像“ Baseaddress”那样不可变。

我们应该如何使用需要httpclient作为依赖性的第三方利率?

第三方LIB可以使用线程安全方法或更改不变的成员。

我应该为每个第三方lib创建一个客户吗?
假设第三方LIB会以“正确”方式使用HTTPCLEINT是“保存”吗?


PS在Stackoverflow上问的第二个问题。请不要杀了我问。

Example initial situation:

Lets say I have a web api with dependency injection.
I normally would bind one HttpClient as singleton.

I think the HttpClient is regarded as mostly thread-safe.
https://codereview.stackexchange.com/questions/69950/single-instance-of-reusable-httpclient
(top answer - the three links)

But some member are not immutable like the 'BaseAddress'.

How should we use third-party-libs that need a HttpClient as dependency?'

The third-party-lib could use not thread-safe methods or change the not immutable members.

Should I create one client for every third-party-lib?
Is it 'save' to assume that the third-party-lib will use the HttpClient in the 'correct' way?


p.s second question asked on stackoverflow. Please don't kill me for asking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文