【问题标题】:NestJS Injecting request or execution context in servicesNestJS 在服务中注入请求或执行上下文
【发布时间】:2019-03-30 05:16:10
【问题描述】:

如何在服务中注入请求或执行上下文?

【问题讨论】:

    标签: javascript node.js typescript dependency-injection nestjs


    【解决方案1】:

    从 6.0 版本开始,可以将当前请求注入到服务中,使用 REQUEST 令牌:

    export class AppService {
      constructor(@Inject(REQUEST) private request) {}
    
      load() {
        const user = this.request.user;
      }
    }
    

    【讨论】:

    • 执行上下文呢?
    猜你喜欢
    • 2021-12-29
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 2019-02-26
    • 2019-12-26
    相关资源
    最近更新 更多