Wiring 100 Controllers by Hand

Why a controller needs its service handed to it through a constructor, and the real cost of wiring dozens of controllers, services, and repositories by hand in the right order.

September 1, 20261 min read32 / 43

TicketController can't call TicketService without holding a reference to it first, and that reference has to come from somewhere.

A Constructor Hands the Controller Its Service

The controller takes a TicketService through its own constructor, wiring the dependency explicitly by hand rather than through any container magic — the same discipline this series committed to back when framework philosophy first came up, now applied to a real, working controller instead of an abstract argument.

The Real Cost of Wiring Everything Yourself

Wiring one controller to one service by hand is trivial. A real codebase doesn't stop at one controller. Twenty, thirty, even more real controllers are completely ordinary in a working system, and each one needs its own dependencies constructed and handed to it.

That's not just a lot of typing. Every one of those objects has to be created in the right order, repositories before the services that depend on them, services before the controllers that depend on those. Getting that order right by hand, across dozens of objects with their own nested dependencies, is exactly the kind of mechanical, error-prone work a framework exists to take off a developer's hands.