grpc / grpc-dotnet

gRPC for .NET
Apache License 2.0
4.2k stars 769 forks source link

Proposal: add MapGrpcService overload for ServerServiceDefinition #2236

Open aka-nse opened 1 year ago

aka-nse commented 1 year ago

related to: #1628

Current Grpc.AspNetCore.Server does not support ServerServiceDefinition. This makes some obstacle for:

Then I propose new API:

public static class GrpcEndpointRouteBuilderExtensions
{
    public static GrpcServiceEndpointConventionBuilder MapGrpcService(
        this IEndpointRouteBuilder builder,
        ServerServiceDefinition serviceDefinition)
        => throw new NotImplementedException();

    public static GrpcServiceEndpointConventionBuilder MapGrpcService(
        this IEndpointRouteBuilder builder,
        Func<IServiceProvider, ServerServiceDefinition> getServiceDefinition)
        => throw new NotImplementedException();
}

It looks that current implementation in this project is mismatch with the new APIs, then I implement these API experimentally on https://github.com/aka-nse/grpc-dotnet/tree/feature/MapGrpcService-with-ServerServiceDefinition. GreeterByServiceDefinition is a new sample solution for this API.

NOTE: Conventional API can delay instantiation of service until RPC routing, but I think there is a limitation in new API that the service instance shall be instantiated at mapping immediately.

gtachev-infragistics commented 5 days ago

Do you know if this PR is planned to be merged soon? We have a lot of code to refactor and seems that this can save us a lot of time.