swift-dependency-injection
Installation
SKILL.md
Swift Dependency Injection
When to invoke
- Designing a new service boundary (CloudKit, networking, clock, RNG, notifications).
- Asking "how do I make this testable", "how do I inject X", or "should I use a singleton here".
- Establishing a composition root for a new app target or module.
- Reviewing code that reaches out to global state,
URLSession.shared,Date(), orUUID(). - Choosing between constructor injection and SwiftUI environment injection.
Scope
Owns how a seam is shaped and injected (protocol / struct witness / environment / task-local) and how a fake is written. Does NOT own the test framework, snapshot tooling, or where shared fake types live → swift-testing-baseline (<Project>KitTesting); nor the target layout that hosts the composition root → swiftpm-modularization.
Inject via
Three routing decisions, front-loaded (details in the sections below):