Question: HttpClientFactory custom http message handlers
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- csharp
调研方向
首先阅读 HttpClientFactory.CreateHandler(CreateHttpClientArgs args) 以及 issue 中展示的 IHttpMessageHandlerFactory 用法,然后检查现有的 SDK 注册和初始化流程。当多个由 DI 解析的 handler 可以在不丢失 gzip、user-agent 配置或其他 SDK 初始化器的情况下复用时,即视为完成;未指定任何文件或测试路径。
由索引模型根据 Issue 内容生成。
描述
Hello,
do you have an example, how we can extend http client factory to add multiple http message handlers and keep current implementation of google http client factory? In essence, I have multiple handlers covering cross cutting concerns (traces, metrics, logs) which I am using with other typed http clients, I would like them to be reused. Ideally it would the best to resolve them from DI.
I have found similar issue in other library which uses google http client factory ref: https://github.com/googleapis/google-api-dotnet-client/issues/1756, however some of the implementation is missing in current.
For now I have implemented as such (since I could not find any other possible way)
// configure handlers, so I could resolve through IHttpMessageHandlerFactory
builder.Services.AddHttpClient("Firebase")
.ConfigurePrimaryHttpMessageHandler(_ => // some proxy configuration)
.AddHttpMessageHandler<CorrelationIdHandler>()
.AddHttpMessageHandler<LoggingHandler>()
.AddHttpMessageHandler<TracingHandler>();
// override google http client factory
public class FirebaseHttpClientFactory : HttpClientFactory
{
private readonly IHttpMessageHandlerFactory _httpMessageHandlerFactory;
public FirebaseHttpClientFactory(IHttpMessageHandlerFactory httpMessageHandlerFactory)
{
_httpMessageHandlerFactory = httpMessageHandlerFactory
}
protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args)
{
return _httpMessageHandlerFactory.CreateHandler("Firebase");
}
}
// register firebase messaging
builder.Services.AddSingleton(sp => return FirebaseMessaging.GetMessaging(FirebaseApp.Create(new AppOptions{
Credential = // load from file
HttpClientFactory = new FirebaseHttpClientFactory(sp.GetRequiredService<IHttpMessageHandlerFactory>())
}));
By doing this, it kinda works, however I loose a lot of functionality from SDK itself, like gzip, user agent name setter and other initializers.
Can you please confirm that this is the only way currently how to achieve this and whether this will work?
I can see that other google library ref: https://github.com/googleapis/google-api-dotnet-client/issues/1756 already decoupled itself from accepting implementation of google.HttpClientFactory to interface (what let's to use DI and pass multiple handlers).
Are you planning to make similar update to this library? If yes and you need help, please let me know :)
- 主要语言
- C#
- 星标
- 407
- 派生
- 147
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-admin-dotnet 的其他 Issue
-
AbstractFirebaseAuth.cs has a typo (accound/account)可能重新可做 关联的 PR 已关闭且未合并。 未关闭needs-triage
难度 1/5 1 小时以内 新手友好度 72/100
firebase/firebase-admin-dotnet#334 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
firebase/firebase-admin-dotnet#591 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
GetProjectId returns null on Compute Engine / Cloud Run with application default credentials可能已有人在做 @lahirumaramba 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 78/100
firebase/firebase-admin-dotnet#588 ·
维护者通常 1 天内回复
-
Sending FCM notification with Fids Return NotRegistered可能重新可做 @yvonnep165 于 80 天前认领,目前没有进行中的 PR。 未关闭
firebase/firebase-admin-dotnet#534 · 5 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
Sending MulticastMessage does not work after replacing Tokens with Fids可能重新可做 @Doris-Ge 于 108 天前认领,目前没有进行中的 PR。 未关闭api: messaging
firebase/firebase-admin-dotnet#530 · 2 条评论 · 已指派 2 人 ·
维护者通常 1 天内回复
查看 firebase/firebase-admin-dotnet 的全部 Issue
相似的 Issue
-
needs attention untriaged
难度 2/5 1-3 小时 新手友好度 78/100
AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#3666 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
stryker-mutator/stryker-net#3974 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
JiaFeiMiao-K-Cat/DiscImageStudio#171 · 3 条评论 ·
维护者通常 1 天内回复
-
S: Untriaged
难度 1/5 1 小时以内 新手友好度 72/100
DeltaV-Station/Delta-v#6711 ·
维护者通常 1 天内回复