Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M6312

Dependency Injection

Dependency Injection
CreateHigh supportDesign Thinking
Included
account_tree

Updated 2026-07-30

Loading revision record…

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.

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/4

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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.

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Dependency_injectionZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS