Dependency Injection
Updated 2026-07-30
Summary
In software engineering, dependency injection is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to …
Definition
Objects should not create the dependencies they need themselves, but rather have an external container inject the dependency objects at runtime. This implements Inversion of Control (IoC) and reduces coupling. Scaffold use: Plug-and-play resources. Do not bind your capabilities to a specific platform or resource (hardcoding). Design yourself as an 'interface', with required resources (funds, connections) injected externally. This way you can switch platforms at any time without refactoring yourself.
Introduction
How to use
Plug-and-play resources. Do not bind your capabilities to a specific platform or resource (hardcoding). Design yourself as an 'interface', with required resources (funds, connections) injected externally. This way you can switch platforms at any time without refactoring yourself.
Mechanism
An implementation of Inversion of Control (IoC): objects do not create dependencies themselves, but rather an external (container or caller) 'injects' the dependencies at creation time. The object only declares the required interfaces, and the concrete instances are determined externally, thereby reducing coupling and improving testability and replaceability.
Practice
In progress 0/4Practice this model in one real situation:
Cases
- A service class receives a database connection instance instead of connecting itself; a web framework injects request objects into controllers; treat external resources like 'funds/connections' as injectable interfaces, making it easy to switch platforms without refactoring yourself.
Common pitfalls
- Injecting everything leads to over-frameworking; injecting for the sake of injection ignores simplicity; confusing DI with Inversion of Control; misuse makes call chains hard to trace.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Dependency_injectionverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS