コード例 #1
0
ファイル: TestService.cs プロジェクト: yidaibawang/Abp.Grpc
        public UnaryResult <string> PrintCurrentUserId(GrpcSession session)
        {
            Console.WriteLine($"接收客户端传递 Session 值之前,服务端的用户 Id 值: {_tmpAbpSession.UserId}");
            string resultUserIdStr;

            using (_tmpAbpSession.Use(session.TenantId, session.UserId))
            {
                resultUserIdStr = (_tmpAbpSession.UserId ?? 0).ToString();
                Console.WriteLine($"临时变更的 AbpSession 值: {_tmpAbpSession.UserId}");
            }

            Console.WriteLine($"退出 using 语句块时,当前用户的 Id 值: {_tmpAbpSession.UserId}");

            return(new UnaryResult <string>(resultUserIdStr));
        }
コード例 #2
0
        public UnaryResult <long?> TestGrpcSession(GrpcSession session)
        {
            // 赋值前 Session 的值
            Console.WriteLine(_abpSession.UserId);

            // 临时改变 Session 值
            using (_abpSession.Use(session.TenantId, session.UserId))
            {
                Console.WriteLine(_abpSession.UserId);
            }

            // 离开 using 语句时 Session 的值
            Console.WriteLine(_abpSession.UserId);

            return(new UnaryResult <long?>(1000));
        }