InterceptorCallInvoker.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Grpc.Core;
  6. using Grpc.Core.Interceptors;
  7. using Grpc.Extension.Client.Internal;
  8. namespace Grpc.Extension.Client.Interceptors
  9. {
  10. /// <summary>
  11. /// 客户端中间件的CallInvoker
  12. /// </summary>
  13. internal class InterceptorCallInvoker : CallInvoker
  14. {
  15. private CallInvoker _interceptorCallInvoker;
  16. public InterceptorCallInvoker(AutoChannelCallInvoker autoChannelCallInvoker, IEnumerable<ClientInterceptor> clientInterceptors)
  17. {
  18. _interceptorCallInvoker = autoChannelCallInvoker.Intercept(clientInterceptors.ToArray());
  19. }
  20. public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
  21. {
  22. return _interceptorCallInvoker.BlockingUnaryCall(method, host, options, request);
  23. }
  24. public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
  25. {
  26. return _interceptorCallInvoker.AsyncUnaryCall(method, host, options, request);
  27. }
  28. public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
  29. {
  30. return _interceptorCallInvoker.AsyncServerStreamingCall(method, host, options, request);
  31. }
  32. public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
  33. {
  34. return _interceptorCallInvoker.AsyncClientStreamingCall(method, host, options);
  35. }
  36. public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
  37. {
  38. return _interceptorCallInvoker.AsyncDuplexStreamingCall(method, host, options);
  39. }
  40. }
  41. }