<aside> 1️⃣ IOC란?
</aside>
<aside> 2️⃣ 예시
</aside>
@Service
public class BookService {
private final BookRepository bookRepository;
@Autowired
public BookService(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}
// 서비스 메소드들...
}
BookService
**는 **BookRepository
**에 의존하고 있다. 스프링 IoC 컨테이너는 **BookService
**가 생성될 때 이 의존성을 주입해 준다.
이는 @Autowired
어노테이션을 통해 가능하며, 이를 통해 개발자는 직접 **BookRepository
**를 생성하거나 관리할 필요가 없다. 이렇게 제어가 사용자(개발자)에서 프레임워크(여기서는 스프링)로 역전된 것이다.따라서 IoC는 코드의 결합도를 줄이고 유연성과 확장성을 증가시키는 데 큰 도움이 된다. 이는 소프트웨어 설계의 SOLID 원칙 중 하나인 **Dependency Inversion Principle (의존 역전 원칙)**과도 깊은 연관이 있다.