dependency injection
Supply a collaborator through a contract instead of constructing it inside.
Use this when The same behavior needs local, remote, or test implementations.
without the term
“This class creates its own database client inside, so I can't use a fake one in tests or a different store locally. Can you change it so whoever uses it passes in what it should use?”
with the term · How do you ask a model for dependency injection?
Use dependency injection for this store. Keep the consumer on a small contract and verify it with real and in-memory implementations.
What is dependency injection?
Dependency injection makes a consumer receive the implementation it uses. A function argument is often enough.
Why does dependency injection matter when vibe coding?
A component coupled to one concrete store is hard to reuse or test.
How do you do dependency injection?
Name the operations the consumer needs. Check it with two implementations of that contract.
What goes wrong with dependency injection?
The interface copies every method of the underlying library.