cyanfish / grpc-dotnet-namedpipes

Named pipe transport for gRPC in C#/.NET
Apache License 2.0
183 stars 47 forks source link

Interceptor support #29

Open joschmo80 opened 2 years ago

joschmo80 commented 2 years ago

Hello,

I have a .NET 5.0 app that uses gRpc and your package to perform IPC. I wish to add interceptors for global logging, error handling, and profiling. I attempted the solution in https://stackoverflow.com/questions/55630096/grcp-intercept-calls-in-c-sharp, but could not see a way to add the interceptor. That is b/c, per your README, the proper way to bind the service is via:

Greeter.BindService(server.ServiceBinder, new GreeterService());

Which (as best I can tell) does not provide access to the .Intercept API. Any suggestions?

Thanks!

cyanfish commented 2 years ago

If you're willing to use some reflection, something like this should work:

var def = Greeter.BindService(new GreeterService());
var def2 = def.Intercept(...); // Needs a Grpc.Core reference
def2.BindService(server.ServiceBinder); // BindService is internal to Grpc.Core.Api so you'll need reflection to do this call
joschmo80 commented 2 years ago

Sorry, just getting around to looking at this now. I now realize that the Intercept API requires Grpc.Core, which will be deprecated per https://grpc.io/blog/grpc-csharp-future/.

Would it be possible to provide an Intercept API that doesn't require reflection or reference to Grpc.Core?

Also, and somewhat related: Can you provide any advice on this package (GrpcNamedPipes) vs. https://docs.microsoft.com/en-us/aspnet/core/grpc/interprocess?view=aspnetcore-6.0 ? I love your library b/c it is easy to setup and use, but am wondering if it is better to go with something officially supported by the gRpc team.

As always, thanks for your help - much appreciated!

cyanfish commented 2 years ago

Thanks for the link, I didn't realize that had been implemented - Unix domain sockets should be comparable to named pipes, providing you're using Windows 10.

This library will still have advantages in terms of being lightweight (and probably better performance but I'd need to test). But otherwise Kestrel would be a good solution, especially if you need features I haven't implemented.

NeverMorewd commented 8 months ago

Sorry, just getting around to looking at this now. I now realize that the Intercept API requires Grpc.Core, which will be deprecated per https://grpc.io/blog/grpc-csharp-future/.

Would it be possible to provide an Intercept API that doesn't require reflection or reference to Grpc.Core?

Also, and somewhat related: Can you provide any advice on this package (GrpcNamedPipes) vs. https://docs.microsoft.com/en-us/aspnet/core/grpc/interprocess?view=aspnetcore-6.0 ? I love your library b/c it is easy to setup and use, but am wondering if it is better to go with something officially supported by the gRpc team.

As always, thanks for your help - much appreciated!

+1