Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
nestjs: property not available in the current context error

I'm trying to use a service inside a decorator and this decorator is used over ServiceX function, which is called from some serviceY. However getting an error. Spent quite a long time with no success. Any help will be appreciated.

Error: Nest can't resolve dependencies of ServiceX. Please make sure that the "logger" property is available in the current context.
// myDecortor.ts

import { Inject } from '@nestjs/common';
import { LoggerService } from '../../logger/logger.service';

export function myDecorator(bubble = true) {
  const injectLogger = Inject(LoggerService);

  return (target: any, propertyKey: string, propertyDescriptor: PropertyDescriptor) => {
    injectLogger(target, 'logger');  // This logger property is not accessible to ServiceX

    //get original method
    const originalMethod = propertyDescriptor.value;

    //redefine descriptor value within own function block
    propertyDescriptor.value = async function(...args: any[]) {
      // something
    };
  };
}

importing LoggerModule in ServiceXModule

// serviceX.module.ts

import { LoggerModule } from '../../logger/logger.module';
/// .....

@Module({
  imports: [LoggerModule],
  providers: [serviceX],
  exports: [ServiceX],
})


Using decortor over a method of ServiceX class.

// serviceX.service.ts

import { myDecorator } from '../logger/myDecorator';

@myDecorator()
async serviceXfunction() {
  //some more stuff
}

Importing serviceX module in ServiceY

// serviceY.module.ts

import { ServiceXModule } from '../../logger/serviceX.module';
/// .....

@Module({
  imports: [ServiceXModule],
  providers: [serviceY],
  exports: [ServiceY],
})


// serviceY.service.ts

import { ServiceX } from '../logger/serviceX.service';

constructor(private readonly serviceX: ServiceX){}

async serviceYfunction() {
  await serviceX.serviceXfunction();
}

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda