I have a service which I can inject into other components without any issues.
When I try to inject that service into another service I get
Error: Nest can't resolve dependencies of the AService (?).
Please make sure that the argument BService at index [0] is available in the AService context.
I cannot find any way to inject services into each other. Is this not supported, kind of an anti-pattern.... ?
And if so, how to handle a service with functionality I want to be available in all of my app in several components and services?
Code as follows:
b.module.ts
import { Module } from '@nestjs/common';
import { BService } from './b.service';
@Module({
imports: [],
exports: [bService],
providers: [bService]
})
export class bModule { }
b.service.ts
import { Injectable } from '@nestjs/common';
@Injectable()
export class BService {
someFunc();
}
a.module.ts
import { Module } from '@nestjs/common';
import { SensorsService } from './a.service';
import { SensorsController } from './a.controller';
import { BModule } from '../shared/b.module';
@Module({
imports: [BModule],
providers: [AService],
controllers: [AController],
exports: []
})
export class AModule {
}
a.service.ts - which should be able to use b.service
import { Injectable } from '@nestjs/common';
import { BService } from '../shared/b.service';
@Injectable()
export class AService {
constructor(
private bService: BService
) {}
someOtherFunc() {}
}
bModule, but then you're importingBModule- is this the issue? Same with thebServiceAppModuleif that is not the case?