grpc / grpc/grpc-dotnet

Pass the type of client to GrpcClientFactoryOptions.Creator to activate

Open
#1,346 2 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.
Currently, [`GrpcClientFactoryOptions.Creator`](https://github.com/grpc/grpc-dotnet/blob/bf26e0377abfa86f34778ee1347565f02d90ffb5/src/Grpc.Net.ClientFactory/GrpcClientFactoryOptions.cs#L50) can implement custom client generation, but the client type is not passed to the `Creator` delegate, so we cannot generate a custom client.

The default activation process is to pass a type parameter to the `IServiceProvider` when requesting a `DefaultClientActivator`, so the client type is passed to the `DefaultClientActivator`.
https://github.com/grpc/grpc-dotnet/blob/bf26e0377abfa86f34778ee1347565f02d90ffb5/src/Grpc.Net.ClientFactory/Internal/DefaultGrpcClientFactory.cs#L50

### Describe the solution you'd like
We want to receive the client's type in a custom delegate or make ClientActivator service replaceable.

```csharp
public Func? Creator { get; set; }
```
```csharp
var c = clientFactoryOptions.Creator(callInvoker, typeof(TClient));
```

### Additional context
Our [MagicOnion](https://github.com/Cysharp/MagicOnion) project relies on Grpc.Net, but has its own implementation at the client layer.

Contributor guide

Open the contributing guide

Research direction

Start in src/Grpc.Net.ClientFactory/GrpcClientFactoryOptions.cs at the Creator delegate, then read src/Grpc.Net.ClientFactory/Internal/DefaultGrpcClientFactory.cs around the DefaultClientActivator lookup. Update the custom creation path so it receives the client type as requested, and verify that the factory invokes the delegate with both the CallInvoker and typeof(TClient).

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.