private IUnitOfWork CreateUnitOfWork(MethodInfo methodInfo)
        {
            var unitOfWork = ScopeServiceProvider.GetService <IUnitOfWork>();

            if (unitOfWork != null)
            {
                var unitOfWorkAttr = methodInfo.GetCustomAttribute <UnitOfWorkAttribute>();
                if (unitOfWorkAttr != null && unitOfWorkAttr.IsTransactional)
                {
                    unitOfWork.Begin(unitOfWorkAttr.IsolationLevel);
                }
            }
            return(unitOfWork);
        }
Ejemplo n.º 2
0
        // Server side handler of the SayHello RPC
        public override async Task <HelloReply> SayHello(HelloRequest request, ServerCallContext context)
        {
            var client = ScopeServiceProvider.GetService <MathGrpc.MathGrpc.MathGrpcClient>();

            //调用服务端流方法
            //var result = client.SumServerStream(new MathGrpc.SumRequest() { Num = 10 });
            //await result.ResponseStream.ForEachAsync(res =>
            //{
            //    Console.Write(res.Value);
            //    return Task.CompletedTask;
            //});

            //调用客务端流方法
            //var result = client.Sum();
            //await result.RequestStream.WriteAsync(new MathGrpc.SumRequest() { Num = 14 });
            //await result.RequestStream.WriteAsync(new MathGrpc.SumRequest() { Num = 15 });
            //await result.RequestStream.CompleteAsync();
            //Console.WriteLine(result.ResponseAsync.Result);
            return(new HelloReply {
                Message = "Hello " + request.Name
            });
        }