Skip to content

Instantly share code, notes, and snippets.

@vivainio
Created April 14, 2020 17:45
Show Gist options
  • Save vivainio/6947d10a4c8cfc56c5d0e4c08c43e1d2 to your computer and use it in GitHub Desktop.
Save vivainio/6947d10a4c8cfc56c5d0e4c08c43e1d2 to your computer and use it in GitHub Desktop.
class SomeGrpcServerInterceptor: Interceptor
{
private IWindsorContainer container;
public P2PGrpcServerInterceptor(IWindsorContainer container)
{
this.container = container;
}
// xxx override others as well?
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context,
UnaryServerMethod<TRequest, TResponse> continuation)
{
try
{
using (GrpcCallScope.Begin(context, container))
{
var ret = await base.UnaryServerHandler(request, context, continuation);
return ret;
}
}
catch (Exception ex)
{
var logger = container.Resolve<ILogger>();
logger.Error($"Error during gRPC call {context.Method} from {context.Peer}", ex);
throw;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment