【发布时间】:2021-07-24 15:00:56
【问题描述】:
我正在尝试从 NestJS 中的另一个类服务扩展一个类服务,并使用 DI 将其加载到第三个服务中。我得到嵌套错误:
Error: Nest can't resolve dependencies of the AlgorithmsService (?, SocketService). Please make sure that the argument Object at index [0] is available in the AlgorithmsModule context.
Potential solutions:
- If Object is a provider, is it part of the current AlgorithmsModule?
- If Object is exported from a separate @Module, is that module imported within AlgorithmsModule?
@Module({
imports: [ /* the Module containing Object */ ]
})
所以如果我检查 algorithm.service.ts
@Injectable()
export class AlgorithmsService {
constructor(public coinMakerService: CoinMakerService,
public socketService: SocketService) { }
}
在 app.module.ts 中
@Module({
imports: [AlgorithmsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
所以 algorithm.module.ts
@Module({
imports: [],
exports: [],
controllers: [AlgorithmsController],
providers: [
AlgorithmsService,
CoinMakerService,
CryptoService,
SocketService
]
})
export class AlgorithmsModule { }
最后是我假装 tyo 扩展的最后一个类:
@Injectable()
export class CryptoService {
constructor() { }
}
@Injectable()
export class CoinMakerService extends CryptoService {
constructor() {
super()
}
}
我不知道我是否需要声明其他任何内容。我试图将所有服务移动到一个共享模块并从顶级 app.module.ts 导入它,但我得到了同样的错误。
【问题讨论】:
标签: javascript angular dependency-injection nestjs