Dependency Injection Without the Framework Hype

Dependency injection (DI) sounds like enterprise jargon, but the idea is simple and it shows up in object-oriented design interviews and code reviews all the time.

The idea

A class should receive the things it depends on instead of creating them itself.

Without DI, an OrderService constructs its own PostgresOrderRepository and SmtpEmailSender inside its constructor. It is now welded to a database and a mail server.

With DI, OrderService takes an OrderRepository and an EmailSender as constructor parameters. Whoever builds the service decides which implementations to pass.

Why it matters

Styles

Do you need a container?

Containers (Spring, .NET's built-in container, Dagger, Guice) automate wiring in large apps. For small and medium services, manual wiring in one composition root (main function) is often clearer: plain code, no reflection, and errors at compile time. In Go and many Python codebases, manual DI is the norm.

Common mistakes

Interview tip

When an interviewer asks how you would test a class that sends emails or reads the current time, answer with DI: inject an EmailSender and a Clock, then pass fakes in tests.

Disclosure: I work with the Linkjob AI team, makers of an AI interview copilot (Linkjob AI).