-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BindServiceAttribute #18484
Add BindServiceAttribute #18484
Conversation
btw I don't have all of the C++ tools setup on this computer. Hopefully it compiles 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting is off (we enforce clang format on C/C++ code).
+ tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
--- /var/local/git/grpc/src/compiler/csharp_generator.cc 2019-03-24 20:29:22.482677999 +0000
+++ /tmp/tmp.b6a8NEqD8T 2019-03-24 20:32:14.650677999 +0000
@@ -383,7 +383,8 @@
"$servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print(
- "[grpc::BindService(typeof($classname$), nameof($classname$.BindService))]\n",
+ "[grpc::BindService(typeof($classname$), "
+ "nameof($classname$.BindService))]\n",
"classname", GetServiceClassName(service));
out->Print("public abstract partial class $name$\n", "name",
GetServerClassName(service));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments (and I pushed a fix for one of them and the regenerated code).
src/compiler/csharp_generator.cc
Outdated
@@ -382,6 +382,10 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor* service) { | |||
"/// <summary>Base class for server-side implementations of " | |||
"$servicename$</summary>\n", | |||
"servicename", GetServiceClassName(service)); | |||
out->Print( | |||
"[grpc::BindService(typeof($classname$), " | |||
"nameof($classname$.BindService))]\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameof()
is a C# 6 concept and as of now, the generated code does not require C# 6. I know C# 6 is pretty old already, but we can easily use a string "BindService"
instead of nameof() and remove the concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetServiceClassName(service)
only gives the name of the class, but we should probably use a fully qualified name to eliminate potential name collisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we should probably use a fully qualified name to eliminate potential name collisions.
I thought about that but there are other places in the generated service that reference class names without fully qualifying them.
src/csharp/Grpc.Examples/MathGrpc.cs
Outdated
@@ -67,6 +67,7 @@ public static partial class Math | |||
} | |||
|
|||
/// <summary>Base class for server-side implementations of Math</summary> | |||
[grpc::BindService(typeof(Math), "BindService")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: TBH i'm still not 100% convinced by the name [BindService]
, I don't feel the name fully conveys what the attribute stands for. Have we considered some alternative names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to alternatives.
[ServiceBind(...)]
[ServiceBinder(...)]
[ServiceBindMethod(...)]
[BindMethod(...)]
@@ -0,0 +1,53 @@ | |||
#region Copyright notice and license | |||
// Copyright 2015 gRPC authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2019
Does anything else need to be done here? Can we merge this for 1.20? I'm ok with |
@JamesNK I thought we left the exact attribute name and arguments open in relation to Server Reflection as "needs more thought". |
I implemented server reflection here - https://github.com/grpc/grpc-dotnet/pull/192/files#diff-811a02dca4701b0d502640e0d18407b7R48 I've thought about it and there are three choices:
I'm ok with 3. |
I slightly perfer |
I chose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Add a BindServiceAttribute so .NET libraries can easily resolve the location of the bind service method for a gRPC service.
// @jtattermusch
grpc/grpc-dotnet#107