Я использую Nest JS
в Backend. У меня есть служба ведения журнала 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 я пытаюсь определить useGlobalInterceptors
в обход экземпляр Logging service
. Тем не менее, он выдает ошибку на 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.