【发布时间】:2020-06-04 16:20:31
【问题描述】:
我在后端使用Nest JS。我有日志服务scoped.Request
@Injectable({ scope: Scope.REQUEST })
export class LoggingService extends BaseLoggerService implements LoggerService {
constructor(readonly configService: ConfigurationService, @Inject(RequestContextService) readonly requestContextService: IRequestContextService) {}
我有需要日志服务的全局拦截器。
@Injectable()
export class LoggingInterceptor implements NestInterceptor {
constructor(@Inject(LoggingService) private readonly logger: LoggingService) {
} }
现在在 app.ts 中,我试图绕过 Logging service 的实例来定义 useGlobalInterceptors。但是,它会在npm run start 上引发错误。
app.useGlobalInterceptors(new LoggingInterceptor(app.get(LoggingService)));
错误
2020-02-20T10:51:54.409Z ERROR [object Object] (RID:NOT_SET RP:NOT_SET TK:) (AN:NOT_SET COM:NOT_SET UAN:NOT_SET) LoggingService is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead. Error: LoggingService is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.
【问题讨论】:
标签: angular interceptor nestjs