Skip to content

Dependency Injection

Stable ID: pattern.dependency-injection
Kind: design-pattern
Status: stable
Source: skill/references/design-patterns/dependency-injection.md

Purpose

Supply collaborators explicitly at construction or call boundaries so lifecycle and substitution remain visible.

Use when

  • A component has infrastructure collaborators or multiple implementations.
  • Tests need deterministic substitutes without global mutation.

Avoid when

  • A service locator or container would hide ownership.
  • Simple pure functions have no collaborators to inject.

Applicability

  • Languages: any, python, q-kdbplus, cpp, rust, dart-flutter, typescript
  • Related entries: component.configuration