Esempio n. 1
0
        protected override void AddGenericBlockingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, TReturn> serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            IGrpcMethodBinder binder)
        {
            var serializer = serviceStub.Serializer;

            Task <RpcResponse <TResponseReturn> > handler(TRequest request, GrpcCore.ServerCallContext context)
            {
                using (var serviceScope = CreateServiceScope(serviceStub))
                {
                    return(serviceStub.CallBlockingMethod(
                               request, new GrpcCallContext(context), serviceCaller, responseConverter,
                               faultHandler, serializer, serviceScope?.ServiceProvider).AsTask());
                }
            }

            binder.AddMethod(
                GrpcMethodDefinition.Create <TRequest, RpcResponse <TResponseReturn> >(GrpcCore.MethodType.Unary,
                                                                                       operationInfo.FullServiceName, operationInfo.Name, serializer),
                handler);
        }
Esempio n. 2
0
        protected override void AddGenericBlockingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, 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.CallBlockingMethod(
                request,
                new GrpcCallContext(context),
                serviceCaller,
                responseConverter,
                faultHandler,
                serializer,
                activator.ServiceProvider).AsTask();

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

            binder.AddUnaryMethod(methodStub, operationInfo.Metadata, Handler);
        }
        protected override void AddGenericBlockingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, 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.CallBlockingMethod(request, context, serviceCaller, responseConverter, faultHandler, serializer, serviceProvider);

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

            binder.AddMethod(methodStub);
        }