How to use service to an other service with Injectable and different Value in NestJs?

79 Views Asked by At

I have a problem in Nest.js: think about it you have 3 module in nest that name is (a1,b1,c1) (c1) is a class and have a constructor(name,age,lastName) this code is:

@Injectable()
export class Cservice {
  private name: string;
  private lastName: string;
  private age: number;

  constructor(name: string, lastName: string, age: number) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
  }

  async information() {
    return this.age + this.lastName + this.name;
  }
}

and you need to use this class to (a1) and (b1) << withOut use inheritance >> that means (a1) & (b1) wiht different value and donont use new Cservice(...) and all use with provide in nestjs

I mock the value in both Module (a1) & (b1) with {useClass,useValue} but nest.js error say you should define in app.module and when log in c1.service logs all value Moc in app.module,b1.module ,a1.module

0

There are 0 best solutions below