public UnaryServerCallHandler( Method <TRequest, TResponse> method, UnaryServerMethod <TService, TRequest, TResponse> invoker, GrpcServiceOptions serviceOptions, ILoggerFactory loggerFactory) : base(method, serviceOptions, loggerFactory) { _invoker = invoker; if (!ServiceOptions.Interceptors.IsEmpty) { UnaryServerMethod <TRequest, TResponse> resolvedInvoker = async(resolvedRequest, resolvedContext) => { var activator = resolvedContext.GetHttpContext().RequestServices.GetRequiredService <IGrpcServiceActivator <TService> >(); TService?service = null; try { service = activator.Create(); return(await _invoker(service, resolvedRequest, resolvedContext)); } finally { if (service != null) { activator.Release(service); } } }; var interceptorPipeline = new InterceptorPipelineBuilder <TRequest, TResponse>(ServiceOptions.Interceptors); _pipelineInvoker = interceptorPipeline.UnaryPipeline(resolvedInvoker); } }
public UnaryServerCallHandler( Method <TRequest, TResponse> method, UnaryServerMethod <TService, TRequest, TResponse> invoker, GrpcServiceOptions serviceOptions, ILoggerFactory loggerFactory, IGrpcServiceActivator <TService> serviceActivator, IServiceProvider serviceProvider) : base(method, serviceOptions, loggerFactory, serviceActivator, serviceProvider) { _invoker = invoker; if (ServiceOptions.HasInterceptors) { UnaryServerMethod <TRequest, TResponse> resolvedInvoker = async(resolvedRequest, resolvedContext) => { GrpcActivatorHandle <TService> serviceHandle = default; try { serviceHandle = ServiceActivator.Create(resolvedContext.GetHttpContext().RequestServices); return(await _invoker(serviceHandle.Instance, resolvedRequest, resolvedContext)); } finally { if (serviceHandle.Instance != null) { ServiceActivator.Release(serviceHandle); } } }; var interceptorPipeline = new InterceptorPipelineBuilder <TRequest, TResponse>(ServiceOptions.Interceptors, ServiceProvider); _pipelineInvoker = interceptorPipeline.UnaryPipeline(resolvedInvoker); } }
public UnaryServerCallHandler( Method <TRequest, TResponse> method, UnaryServerMethod <TService, TRequest, TResponse> invoker, MethodContext methodContext, ILoggerFactory loggerFactory, IGrpcServiceActivator <TService> serviceActivator, IServiceProvider serviceProvider) : base(method, methodContext, loggerFactory, serviceActivator, serviceProvider) { _invoker = invoker; if (MethodContext.HasInterceptors) { var interceptorPipeline = new InterceptorPipelineBuilder <TRequest, TResponse>(MethodContext.Interceptors, ServiceProvider); _pipelineInvoker = interceptorPipeline.UnaryPipeline(ResolvedInterceptorInvoker); } }