Skip to content
Commitwise
Menu

Inversion of control

Also called: IoC

A design where a framework creates your objects and calls your code, instead of your code creating everything and calling the framework.

Definition

With inversion of control, your classes declare what they need and a container (Spring's ApplicationContext, Hilt, a composition root you write yourself) builds the object graph and decides when your code runs. Dependency injection is the most common form. It keeps classes focused on their job and makes them easy to test with fakes.

In practice

You never call new OrderService(...) in a Spring app; Spring creates it and passes it to the controller that needs it.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.