DI 3

NestJS - Provider와 Nest IoC Container

왜 그랬는지는 모르겠지만 Typescript Type Challenge를 하다가 갑자기 Provider에 대한 궁금증이 생겼다. Provider NestJS의 Provider는 Providers are a fundamental concept in 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 oth..

Backend/NestJS 2023.03.18

Dependency Injection(의존성 주입 - DI)란?

NestJS 공부할 때부터 접하던 개념인데 이번에 Spring을 공부하면서 제대로 짚고 넘어가야겠단 생각이 들었다. Dependency Injection 만약 A 객체가 B 객체의 변화에 영향을 받는다면 A는 B를 의존한다고 한다. 예를 들면 아래와 같다. public class UserService { private final UserRepository users = new MemoryUserRepository(); ... } 위의 UserService는 MemoryUserRepository를 의존한다고 할 수 있다. MemoryUserRepository가 변한다면, 결국 UserService도 변화하게 되는 것이다. 소프트웨어 엔지니어링에서 의존성 주입이란 하나의 객체가 다른 객체의 의존성을 제공하는..

Dev 2022.05.07

Spring Bean 등록하기 - 2가지 방법

Spring Bean 등록 1. 컴포넌트 스캔 원리 @Component annotation 이 있으면 스프링 빈으로 자동 등록됨. Component Scan 은 ComponentScan annotation 가 붙은 package의 하위 package 들을 대상으로 살핀다. (SpringBootApplication annotation 내부에 ComponentScan annotation 존재) 다음 annotation 들은 @Component annotation 가 등록되어있다. @Controller @Service @Repository 스프링은 spring container에 spring bean을 등록할 때, 기본으로 싱글톤으로 등록한다 따라서 같은 스프링 빈이면 모두 같은 인스턴스다. (설정으로 싱글톤..

Backend/Spring 2022.05.03