Cap的问题及解决方法

在使用cap的时候,项目需要访问用户服务信息接口来获取当前信息

但是cap实际上又是通过别的方式或者反射的方式来获取到的,所以他无法知道他使用到的模块数据,这个时候就需要我们手动的去模拟一个作用域来获取上下文信息,并且手动的设置一些需要的信息

手动的去调用我们 使用的接口

        [CapSubscribe("Initialize.TaskStatus", Group = nameof(Priority))]
        public void PriorityCreateBus([FromCap] CapHeader header)
        {
            using var scope = App.Provider.CreateScope();
            var userSession = scope.ServiceProvider.GetRequiredService<IUserSession>();
            userSession.SetToken(header["user_access_token"], header["tenant_access_token"]);
            userSession.GetUserInfo();
            var priority = scope.ServiceProvider.GetRequiredService<IPriority>();
            priority.Create(new PriorityEntity { ForeColor = "#59DBFF", Name = "最低" });
            priority.Create(new PriorityEntity { ForeColor = "#3291F8", Name = "较低" });
            priority.Create(new PriorityEntity { ForeColor = "#FDCA00", Name = "普通" });
            priority.Create(new PriorityEntity { ForeColor = "#FF6200", Name = "较高" });
            priority.Create(new PriorityEntity { ForeColor = "#FF2525", Name = "最高" });

        }

 

posted @ 2022-05-19 23:28  咳咳Pro  阅读(354)  评论(0)    收藏  举报