protected override void AddEventHandlerDefinition <TEventArgs>( RpcEventInfo eventInfo, Func <RpcObjectRequest, IServiceProvider?, IRpcAsyncStreamWriter <TEventArgs>, IRpcContext, ValueTask> beginEventProducer, RpcStub <TService> serviceStub, IGrpcMethodBinder binder) { GrpcCore.ServerStreamingServerMethod <RpcObjectRequest, TEventArgs> handler = (request, responseStream, context) => { using (var scope = CreateServiceScope(serviceStub)) { return(beginEventProducer(request, scope?.ServiceProvider, new GrpcAsyncStreamWriter <TEventArgs>(responseStream), new GrpcCallContext(context)).AsTask()); } }; var beginEventProducerName = $"Begin{eventInfo.Name}"; binder.AddMethod( GrpcMethodDefinition.Create <RpcObjectRequest, TEventArgs>( GrpcCore.MethodType.ServerStreaming, eventInfo.FullServiceName, beginEventProducerName, serviceStub.Serializer), 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, 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); }
protected override void AddCallbackMethodCore <TRequest, TReturn, TResponseReturn>( Func <TService, TRequest, Action <TReturn>, CancellationToken, Task> serviceCaller, Func <TReturn, TResponseReturn>?responseConverter, RpcServerFaultHandler faultHandler, RpcStub <TService> serviceStub, RpcOperationInfo operationInfo, IGrpcMethodBinder binder) where TResponseReturn : class { var serializer = serviceStub.Serializer; GrpcCore.ServerStreamingServerMethod <TRequest, TResponseReturn> handler = (request, responseStream, context) => { using (var serviceScope = CreateServiceScope(serviceStub)) { return(serviceStub.CallCallbackMethod( request, serviceScope?.ServiceProvider, new GrpcCallContext(context), new GrpcAsyncStreamWriter <TResponseReturn>(responseStream), serviceCaller, responseConverter, faultHandler, serializer).AsTask()); } }; binder.AddMethod( GrpcMethodDefinition.Create <TRequest, TResponseReturn>( GrpcCore.MethodType.ServerStreaming, operationInfo.FullServiceName, operationInfo.Name, serviceStub.Serializer), handler); }
protected override void AddCallbackMethodCore <TRequest, TReturn, TResponseReturn>( Func <TService, TRequest, Action <TReturn>, CancellationToken, Task> serviceCaller, Func <TReturn, TResponseReturn>?responseConverter, RpcServerFaultHandler faultHandler, RpcStub <TService> serviceStub, RpcOperationInfo operationInfo, INetGrpcBinder <TService> binder) { var serializer = serviceStub.Serializer; ServerStreamingServerMethod <NetGrpcServiceActivator <TService>, TRequest, TResponseReturn> handler = (activator, request, responseStream, context) => { return(serviceStub.CallCallbackMethod( request, activator.ServiceProvider, new GrpcCallContext(context), new GrpcAsyncStreamWriter <TResponseReturn>(responseStream), serviceCaller, responseConverter, faultHandler, serializer).AsTask()); }; var methodStub = GrpcMethodDefinition.Create <TRequest, TResponseReturn>( MethodType.ServerStreaming, operationInfo.FullServiceName, operationInfo.Name, serializer); binder.AddServerStreamingMethod(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, 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); }
public void OnServiceMethodDiscovery(ServiceMethodProviderContext <NetGrpcServer> context) { context.AddUnaryMethod(GrpcMethodDefinition.Create <RpcObjectRequest, RpcServicesQueryResponse>( GrpcCore.MethodType.Unary, "SciTech.Rpc.RpcService", "QueryServices", this.server.Serializer), new List <object>(), NetGrpcServer.QueryServices);// (s, request, context) => Task.FromResult(s.QueryServices(request))); }
protected override void BuildServiceStubs() { var grpcServer = this.grpcServer ?? throw new InvalidOperationException("BuildServiceStubs should not be called after shutdown"); var queryServiceMethodDef = GrpcMethodDefinition.Create <RpcObjectRequest, RpcServicesQueryResponse>(GrpcCore.MethodType.Unary, "SciTech.Rpc.RpcService", "QueryServices", this.Serializer); var rpcServiceBuilder = new GrpcCore.ServerServiceDefinition.Builder(); rpcServiceBuilder.AddMethod(queryServiceMethodDef, this.QueryServices); var rpcServiceDef = rpcServiceBuilder.Build(); grpcServer.Services.Add(rpcServiceDef); base.BuildServiceStubs(); }
protected override void AddEventHandlerDefinition <TEventArgs>( RpcEventInfo eventInfo, Func <RpcObjectRequest, IServiceProvider?, IRpcAsyncStreamWriter <TEventArgs>, IRpcContext, ValueTask> beginEventProducer, RpcStub <TService> serviceStub, INetGrpcBinder <TService> binder) { ServerStreamingServerMethod <NetGrpcServiceActivator <TService>, RpcObjectRequest, TEventArgs> handler = (activator, request, responseStream, context) => beginEventProducer(request, activator.ServiceProvider, new GrpcAsyncStreamWriter <TEventArgs>(responseStream), new GrpcCallContext(context)).AsTask(); var beginEventProducerName = $"Begin{eventInfo.Name}"; binder.AddServerStreamingMethod( GrpcMethodDefinition.Create <RpcObjectRequest, TEventArgs>( MethodType.ServerStreaming, eventInfo.FullServiceName, beginEventProducerName, serviceStub.Serializer), eventInfo.Metadata, handler); }
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); }