What is the difference between IoC and Dependency Injection? What are a bean and the ApplicationContext?
Short answer
IoC is the principle: your code no longer creates its dependencies, the framework does. DI is how you get IoC: dependencies are passed in; ApplicationContext is the container that creates and manages the beans.
3 points to say:
- IoC is the principle, DI is the technique: dependencies passed in via constructor, setter or field.
- A bean is an object Spring manages;
ApplicationContextis the container: eager singletons, events, profiles, i18n. - The real benefit of DI: tests without a container, and a domain that stays independent of the framework.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.