Video in progress

Junior 🌱 Spring

What do you understand by IoC (Inversion of Control)?

With IoC, control over creating and wiring objects moves from your code to the framework. You say what you need; Spring decides when and how to create it.

📖 Answer

In plain code, you are in control:

OrderService service = new OrderService(new PaymentClient(new HttpClient()));

You build this chain yourself everywhere. With IoC it's the other way round: the class only says "I need a PaymentClient" and doesn't know who creates it or when. Creation, wiring, lifecycle — all of it lives in the container.

In Spring that container is the ApplicationContext. At startup it scans classes, creates beans and puts dependencies in place.

What do you get? Classes become independent of each other, it's easy to pass a mock instead of the real object in tests, and you can swap an implementation without changing code.

IoC is the idea; Dependency Injection is one way to apply it. People mix the two up in interviews.