grpc-dotnet
grpc-dotnet copied to clipboard
Pass the type of client to GrpcClientFactoryOptions.Creator to activate
Is your feature request related to a problem? Please describe.
Currently, GrpcClientFactoryOptions.Creator
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.
public Func<CallInvoker, Type, object>? Creator { get; set; }
var c = clientFactoryOptions.Creator(callInvoker, typeof(TClient));
Additional context
Our MagicOnion project relies on Grpc.Net, but has its own implementation at the client layer.
The Type isn't passed into that method, but you could get a reference it via closure.
The Creator
property was added for protobuf-net. Could you follow what they do to get the type reference: https://github.com/protobuf-net/protobuf-net.Grpc/pull/80/files
Sure, the type can be captured at registration time, and I can fix the problem.
However, considering the behaviour of DefaultClientActivator<TClient>
and a scenario of creating clients dynamically, I think it's not a bad idea to pass the client type to Creator
.