티스토리 뷰

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

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함