Certification/Spring(2V0-72.22, SCP)

What is dependency injection and what are the advantages of using it?

엘호리스 2021. 11. 3. 23:43

'dependency injection'

definition

In software engineering, dependency injection is a technique in which an object receives other objects that it depends on, called dependencies. Typically, the receiving object is called a client and the passed-in object is called a service. The code that passes the service to the client is called the injector. 'Wikipedia'

소프트웨어 공학에서 의존성 주입은 의존이 필요한 객체를 수신하여 의존성을 주입받는 기술이다. 일반적으로, 수신 객체를 클라이언트 그리고 전달된 객체를 서비스 라고 부릅니다. 서비스를 클라이언트에 전달하는 코드를 인젝터라고 합니다. '위키피디아'

types

  1. Constructor Injection

  2. Setter Injection

  3. Interface-based Injection

생성자 주입, 세터 주입, 인터페이스 기반 주입 방식이 있다.

adventages

  • Dependency injection allows a client the flexibility of being configurable.
  • Can be used to externalize a system's configuration details into configuration files, allowing the system to be reconfigured without recompilation.
  • Separate configurations can be written for different situations that require different implementations of components. - This includes, but is not limited to, testing.
  • Due to decoupling, the reusability of the code is increased.
  • Improved code maintainability and testing.
  • It can be applied to legacy code as a code refactoring.
  • The ease of testing is often the first benefit noticed when using dependency injection.
  • It allows reduction of boilerplate code in the application objects, since all work to initialize or set up dependencies is handled by a provider component.