Spring - IOC ( Inversion of Control)
2020. 10. 12. 21:08ㆍ개인공부/스프링
Inversion of Control (뒤바뀐 제어권)
일반적인 (의존성에 대한) 제어권: “내가 사용할 의존성은 내가 만든다.”
class OwnerController {
private OwnerRepository repository = new OwnerRepository();
}
IoC: “내가 사용할 의존성을 누군가 알아서 주겠지”
-
내가 사용할 의존성의 타입(또는 인터페이스)만 맞으면 어떤거든 상관없다.
-
그래야 내 코드 테스트 하기도 편하지.
class OwnerController {
private OwnerRepository repo;
public OwnerController(OwnerRepository repo) {
this.repo = repo;
}
// repo를 사용합니다.
}
class OwnerControllerTest {
@Test
public void create() {
OwnerRepository repo = new OwnerRepository();
OwnerController controller = new OwnerController(repo);
}
}
- 출저 : 인프런, 스프링 입문 - 백기선님.
'개인공부 > 스프링' 카테고리의 다른 글
Spring - Bean (빈) (0) | 2020.10.20 |
---|---|
Spring - JPA에서 실행되는 쿼리로그 를 보는 방법 (0) | 2020.10.13 |
Spring - Bean (빈) (0) | 2020.10.13 |