Provider란?

<aside> 💡 NestJS의 근본적인 Concept중 하나로써, 기본적인 Nest Class 중 상당수는 (service, repository, factories, helpers 등) 은 Provider로 취급 될 수 있다.

</aside>

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" these objects can largely be delegated to the Nest runtime system.

→ 이는 객체가 서로 다양한 관계를 생성할 수 있으며, 이러한 객체를 “wiring up = 연결” 하는 기능은 주로 Nest runtime system에 위임 될 수 있다.

NestJS 공식

NestJS 공식

<aside> 💡 즉, Provider는 다른 클래스에 의존성으로 주입될 수 있는 항목들을 의미한다.

</aside>

Provider 사용법

  1. Provider로 사용할 클래스에 @Injectable 데코레이터를 붙인다.
  2. 해당 Module의 Providers 배열에 추가한다.
  3. 다른 Module에서도 사용하기 위해서는 Exports 배열에 추가하면 된다.