private async Task <TResponse> AwaitInvoker(Task <TResponse> invokerTask, GrpcActivatorHandle <TService> serviceHandle)
 {
     try
     {
         return(await invokerTask);
     }
     finally
     {
         if (serviceHandle.Instance != null)
         {
             await ServiceActivator.ReleaseAsync(serviceHandle);
         }
     }
 }
Beispiel #2
0
        private async Task <TResponse> ResolvedInterceptorInvoker(
            TRequest resolvedRequest, ServerCallContext resolvedContext)
        {
            var service = (TService)ServiceActivator.Create(resolvedContext, typeof(TService));

            try
            {
                return(await _invoker(service, resolvedRequest, resolvedContext));
            }
            finally
            {
                await ServiceActivator.ReleaseAsync(service);
            }
        }
Beispiel #3
0
        private async Task <TResponse> ResolvedInterceptorInvoker(TRequest resolvedRequest, ServerCallContext resolvedContext)
        {
            GrpcActivatorHandle <TService> serviceHandle = default;

            try
            {
                serviceHandle = ServiceActivator.Create(resolvedContext.GetHttpContext().RequestServices);
                return(await _invoker(serviceHandle.Instance, resolvedRequest, resolvedContext));
            }
            finally
            {
                if (serviceHandle.Instance != null)
                {
                    await ServiceActivator.ReleaseAsync(serviceHandle);
                }
            }
        }
        private async Task ResolvedInterceptorInvoker(IAsyncStreamReader <TRequest> requestStream, IServerStreamWriter <TResponse> responseStream, ServerCallContext resolvedContext)
        {
            var service = (TService)ServiceActivator.Create(resolvedContext, typeof(TService));

            try
            {
                await _invoker(
                    service,
                    requestStream,
                    responseStream,
                    resolvedContext);
            }
            finally
            {
                await ServiceActivator.ReleaseAsync(service);
            }
        }
        protected override async Task HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
        {
            // Disable request body data rate for client streaming
            DisableMinRequestBodyDataRateAndMaxRequestBodySize(httpContext);

            TResponse?response = null;

            if (_pipelineInvoker == null)
            {
                GrpcActivatorHandle <TService> serviceHandle = default;
                try
                {
                    serviceHandle = ServiceActivator.Create(httpContext.RequestServices);
                    response      = await _invoker(
                        serviceHandle.Instance,
                        new HttpContextStreamReader <TRequest>(serverCallContext, Method.RequestMarshaller.ContextualDeserializer),
                        serverCallContext);
                }
                finally
                {
                    if (serviceHandle.Instance != null)
                    {
                        await ServiceActivator.ReleaseAsync(serviceHandle);
                    }
                }
            }
            else
            {
                response = await _pipelineInvoker(
                    new HttpContextStreamReader <TRequest>(serverCallContext, Method.RequestMarshaller.ContextualDeserializer),
                    serverCallContext);
            }

            if (response == null)
            {
                // This is consistent with Grpc.Core when a null value is returned
                throw new RpcException(new Status(StatusCode.Cancelled, "No message returned from method."));
            }

            var responseBodyWriter = httpContext.Response.BodyWriter;
            await responseBodyWriter.WriteMessageAsync(response, serverCallContext, Method.ResponseMarshaller.ContextualSerializer, canFlush : false);
        }
        private async Task ResolvedInterceptorInvoker(IAsyncStreamReader <TRequest> requestStream, IServerStreamWriter <TResponse> responseStream, ServerCallContext resolvedContext)
        {
            GrpcActivatorHandle <TService> serviceHandle = default;

            try
            {
                serviceHandle = ServiceActivator.Create(resolvedContext.GetHttpContext().RequestServices);
                await _invoker(
                    serviceHandle.Instance,
                    requestStream,
                    responseStream,
                    resolvedContext);
            }
            finally
            {
                if (serviceHandle.Instance != null)
                {
                    await ServiceActivator.ReleaseAsync(serviceHandle);
                }
            }
        }
        private async Task <TResponse> AwaitServiceReleaseAndReturn(TResponse invokerResult, GrpcActivatorHandle <TService> serviceHandle)
        {
            await ServiceActivator.ReleaseAsync(serviceHandle);

            return(invokerResult);
        }