Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!