Providers/ DI
2022. 9. 4. 16:49ㆍNest.js
Providers는 Nest의 기본 개념이다.
Many of the basic Nest classes may be treated as a provider – services, repositories, factories, helpers, and so on.
The main idea of a provider is that it can be injected as a dependency; this means objects can create various relationships with each other, and the function of "wiring up" instances of objects can largely be delegated to the Nest runtime system.
(한글로 읽으면 더 헷갈리게 나옴)
위 처럼 네스트의 대부분의 클래스는 공급자로 취급 될 수 있고 이를 통해 서로 다양한 관계가 생길 수 있다. 뒤처리는 Nest가 알아서 해줄테니 의존성 주입해서 쓰라는 뜻인듯.
아래 코드에서
Controller - 소비자 , Service - 공급자 ( 소비자가 공급자의 제품을 사용한다. )
constructor(private catsService: CatsService) {} //의존성 주입 예시
//컨트롤러 내에 서비스를 이렇게 주입해주기
export class UsersController {
constructor(private usersService: UsersService){}
}
'Nest.js' 카테고리의 다른 글
미들웨어 (0) | 2022.09.06 |
---|---|
Module / 캡슐화 (0) | 2022.09.04 |
Controller (0) | 2022.09.04 |
DTO & 유효성 검사 (ValidationPipe) (0) | 2022.08.27 |
Nest.js 기본 (0) | 2022.08.26 |