protected override void AddGenericAsyncMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, Task <TReturn> > serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            ILightweightMethodBinder binder)
        {
            var serializer = operationInfo.SerializerOverride ?? serviceStub.Serializer;

            ValueTask <RpcResponse <TResponseReturn> > HandleRequest(TRequest request, IServiceProvider?serviceProvider, LightweightCallContext context)
            => serviceStub.CallAsyncMethod(request, serviceProvider, context, serviceCaller, responseConverter, faultHandler, serializer);

            var methodStub = new LightweightMethodStub <TRequest, RpcResponse <TResponseReturn> >(operationInfo.FullName, HandleRequest, serializer, faultHandler,
                                                                                                  operationInfo.AllowInlineExecution);

            binder.AddMethod(methodStub);
        }
Пример #2
0
        protected override void AddGenericAsyncMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, Task <TReturn> > serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            INetGrpcBinder <TService> binder)
        {
            var serializer = serviceStub.Serializer;

            Task <RpcResponse <TResponseReturn> > Handler(NetGrpcServiceActivator <TService> activator, TRequest request, ServerCallContext context)
            => serviceStub.CallAsyncMethod(
                request, activator.ServiceProvider, new GrpcCallContext(context), serviceCaller,
                responseConverter, faultHandler, serializer).AsTask();

            var methodStub = GrpcMethodDefinition.Create <TRequest, RpcResponse <TResponseReturn> >(
                MethodType.Unary,
                operationInfo.FullServiceName, operationInfo.Name,
                serializer);

            binder.AddUnaryMethod(methodStub, operationInfo.Metadata, Handler);
        }
Пример #3
0
        protected override void AddGenericAsyncMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, Task <TReturn> > serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            IGrpcMethodBinder binder)
        {
            var serializer = serviceStub.Serializer;

            GrpcCore.UnaryServerMethod <TRequest, RpcResponse <TResponseReturn> > handler = (request, context) =>
            {
                using (var callScope = serviceStub.ServiceProvider?.CreateScope())
                {
                    return(serviceStub.CallAsyncMethod(request, callScope?.ServiceProvider, new GrpcCallContext(context), serviceCaller, responseConverter, faultHandler, serializer).AsTask());
                }
            };

            binder.AddMethod(
                GrpcMethodDefinition.Create <TRequest, RpcResponse <TResponseReturn> >(GrpcCore.MethodType.Unary,
                                                                                       operationInfo.FullServiceName, operationInfo.Name, serializer),
                handler);
        }