Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented May 26, 2025

Overall changes in PR:

  • Add example app Definer. Tempoarily references projects instead of nuget packages because nuget packages don't have APIs yet
  • Add new MapGrpcService overloads to accept ServerServiceDefinition type. Binds methods added to the definition.
  • Add support for not creating service instance when invoking endpoint that doesn't need it.
  • Change internal ServerServiceDefinition.BindService method to public.

This PR is a refactor of #2586. Adds same features but remove a lot of duplication.

  • Reusing existing types which have a TService type parameter during binding. Possible by have a special internal service type that isn't created.
  • Supports NativeAOT
  • Update functional tests to build on top of this. Replaces functiona tests previous dynamic method source
  • Rename example app to follow other app names

@JamesNK
Copy link
Member Author

JamesNK commented May 26, 2025

cc @aka-nse

/// Forwards all the previously stored <c>AddMethod</c> calls to the service binder.
/// </summary>
internal void BindService(ServiceBinderBase serviceBinder)
public void BindService(ServiceBinderBase serviceBinder)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aka-nse How was ServerServiceDefinition usable before this change? It doesn't seem like there is any way to access the methods

Copy link
Contributor

@aka-nse aka-nse May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could find, this method was used within ServereServicesDefinitionExtensions.GetCallHandlers in Grpc.Core. In addition, it appears that the method's visibility is overridden using InternalsVisibleToAttribute from Grpc.Core.Api to Grpc.Core.

I do not know why this kind of visibility is used as I do not know gRPC at the time this implementation was written.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think it is fine to make this public. It seems useful, it doesn't leak other API, and eventually removes need for internalsvisibleto which I've found always causes issues eventually.

@JamesNK JamesNK marked this pull request as ready for review May 30, 2025 03:47
@JamesNK JamesNK changed the title GrpcEndpointRouteBuilderExtensions.MapGrpcServiceDefinition refactor MapGrpcServiceDefinition refactor May 30, 2025
@JamesNK JamesNK changed the title MapGrpcServiceDefinition refactor MapGrpcService with service definition refactor May 30, 2025
@JamesNK JamesNK merged commit 44b243f into grpc:master Jun 13, 2025
6 of 7 checks passed
This was referenced Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants