Reputation: 37
I have added MyInterceptor which is being inherited by Grpc.Core.Interceptors.Interceptor:
public class MyInterceptor : Interceptor
{
public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
{
//do something
return base.UnaryServerHandler(request, context, continuation);
}
}
And I am enabling this interceptor in following way:
_server = new Server(channelOptions)
{
Services = { Service.ServerServiceDefinition() },
Ports = { new ServerPort(...) },
};
var interceptor = new MyInterceptor();
foreach(var service in _server.Services)
{
service.Intercept(interceptor);
}
And each time, I called grpc method, the interceptor is not being called.
Thank you very much.
Upvotes: 1
Views: 935
Reputation: 1062770
The Intercept
method returns the decorated ServerServiceDefinition
; as such, you probably want something more like:
var interceptor = new MyInterceptor();
_server = new Server(channelOptions)
{
Services = { Service.ServerServiceDefinition().Intercept(interceptor) },
Ports = { new ServerPort(...) },
};
Upvotes: 1