Exemple #1
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);
        }
Exemple #2
0
        protected override void AddGenericVoidBlockingMethodCore <TRequest>(
            Action <TService, TRequest, CancellationToken> serviceCaller,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            IGrpcMethodBinder binder)
        {
            var serializer = serviceStub.Serializer;

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

            binder.AddMethod(
                GrpcMethodDefinition.Create <TRequest, RpcResponse>(GrpcCore.MethodType.Unary,
                                                                    operationInfo.FullServiceName, operationInfo.Name, serializer),
                handler);
        }
 public void AddMethod <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, GrpcCore.UnaryServerMethod <TRequest, TResponse> handler) where TResponse : class where TRequest : class
 {
     this.stubs.Add(new TestGrpcMethodStub(method, typeof(TRequest), typeof(TResponse), null));
 }
Exemple #4
0
 public void AddMethod <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, GrpcCore.UnaryServerMethod <TRequest, TResponse> handler) where TResponse : class where TRequest : class
 {
     this.builder.AddMethod(method, handler);
 }