grpc / grpc/grpc-dotnet

Support AddAsKeyed on AddGrpcClient

Open
#2,598 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
4.5k
Forks
836
Avg merge
6d 3h
Merged PRs (30d)
7

Description

### Is your feature request related to a problem? Please describe.
I want to used Keyed Services feature with named grpc clients. Right now i have something like this:

```csharp
serviceCollection.AddGrpcClient("custom_name", o =>
{
o.Address = new Uri(someUrl);
});
```

But to access this named client i have to inject `GrpcClientFactory` and all `Create` on it. In .NET 9 `IHttpClientBuilder` introduced `AddAsKeyed` that does exactly that for http clients, but it seems to be ignored for grpc clients.

### Describe the solution you'd like
What i would love to have is that i can inject my named client directly like that:
```csharp
app.MapGet("/", ([FromKeyedServices("custom_name")] MyGrpcServiceClient client) => ... );
```

Contributor guide

Open the contributing guide

Research direction

Start by reading the AddGrpcClient registration path and comparing it with .NET 9's IHttpClientBuilder.AddAsKeyed behavior. Confirm the change should register named gRPC clients for [FromKeyedServices("custom_name")] injection, with direct keyed resolution replacing the need for GrpcClientFactory.Create.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, grpc
Domain
backend, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.