Hand Me What I Need
Hand Me What I Need: Dependency Injection: Hand Me What I Need, Containers: Who Does the Handing Out.
Updated
- Dependency Injection: Hand Me What I Need (Journeyman): When a class builds its own database and reads the real clock, nothing outside it can change either one, so its rules can't be tested; dependency injection has the class ask for them in its constructor, and whoever makes it hands them in, which finishes the idea Pass 1 started with the bakery's settings.
- Containers: Who Does the Handing Out (Journeyman): Once every class asks for what it needs, someone has to make the parts and hand them out; doing it in one place at the start of the app (the composition root) keeps it from being copied everywhere, and a container automates that place, with lifetimes that say whether a part is made once for the app, once per request, or new every time.