티스토리 뷰
NestJs에서 Providers(Service) 싱글톤으로 사용하는 방법
모듈을 Import 해서 사용하라!
You have to export the ItemsService in the module that provides it
@Module({
controllers: [ItemsController],
providers: [ItemsService],
exports: [ItemsService]
})
export class ItemsModule {}
and then import the exporting module in the module that uses the service:
@Module({
controllers: [PlayersController],
providers: [PlayersService],
imports: [ItemsModule]
})
export class PlayersModule {}
⚠️ Don't add the same provider to multiple modules. Export the provider, import the module
https://stackoverflow.com/questions/51819504/inject-nestjs-service-from-another-module
Inject nestjs service from another module
I've got a PlayersModule and an ItemsModule. I want to use the ItemsService in the PlayersService. When I add it by injection: import { Injectable } from '@nestjs/common'; import { InjectModel }...
stackoverflow.com