Glossary

Dependency Injection

Dependency Injection (DI) is a pattern where an object receives its dependencies from the outside rather than creating them itself. Instead of new Mailer() inside a class — Mailer $mailer in the constructor. The class simply declares what it needs.

Why it matters

A class that creates its own dependencies is tightly coupled to their concrete implementations. DI lets you swap implementations — for example, replace a real mailer with a fake one in tests — without changing the class itself.

IoC container

Most frameworks include a built-in container that resolves dependencies automatically: it reads the class constructor, finds registered implementations of interfaces, and injects them. You describe "what is needed" — the container decides "where to get it".

Three injection styles