Beispiel #1
0
        protected override void AddServerStreamingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, IAsyncEnumerable <TReturn> > 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.CallServerStreamingMethod <TRequest, TReturn, TResponseReturn>(
                               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);
        }
Beispiel #2
0
        protected override void AddServerStreamingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, IAsyncEnumerable <TReturn> > 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.CallServerStreamingMethod(
                           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 AddServerStreamingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, IAsyncEnumerable <TReturn> > serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            ILightweightMethodBinder binder)
        {
            var serializer = serviceStub.Serializer;

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

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

            binder.AddMethod(methodStub);
        }