dimitriremoiville/cc-mobile/ios-di
Claude Code and agent skill by dimitriremoiville/cc-mobile
- community
Checking that the SKILL.md file is still in the repository.
Project-specific dependency-injection rules — the `CompositionRoot` in the `App` target, constructor injection through protocols, factory methods for view models, the preview/test container, and when a DI library is actually warranted. Load when adding a type that needs dependencies, wiring a repository, setting up previews, or debugging a DI-related crash.
Install
npx vskill@latest install dimitriremoiville/cc-mobile/ios-diSKILL.md
The same SKILL.md was published earlier as dimitriremoiville/cc-mobile/ios-di.
Dependency injection (project delta)
There is no DI framework here to learn — the pattern is plain Swift initializers. This file documents the rules that make that scale, and the places people reach for a shortcut that breaks testability.
When this applies
Composition root + constructor injection, no container library. On an existing app:
- `swift-dependencies` (
@Dependency(\.apiClient),DependencyValues) → keep it. It solves the same problem with per-test overrides; don't unwind it. The "no service locator, no singletons" spirit still applies. - Factory / Resolver / Swinject (
Container.shared.resolve(...)) → keep it, but the service-locator failure mode is real: flag types that resolve dependencies inside themselves rather than receiving them. - TCA → it already uses
swift-dependencies; skip this skill. - Singletons throughout (
APIClient.shared,UserManager.shared) → say plainly that it blocks testing, but don't refactor the app's wiring as a side effect of an unrelated change.
The composition root
One type, built once at launch, living in the App target — the only place that knows concrete implementations exist:
The scaffolded template is in ${CLAUDE_PLUGIN_ROOT}/skills/ios-app-skeleton/references/app-target.md.
The four rules
- `CompositionRoot.live` is the only shared instance in the app. No other
static let shared. If you're tempted, you want a factory method on the root instead. - Never pass the root into a view model. That's a service locator wearing a struct's clothes: the view model's initializer stops declaring what it needs, and tests have to build the whole graph. Give it the specific use cases.
- Initializer injection only. No optional-var-then-assign wiring, no setter injection. If a type can exist in a half-configured state, it will.
- Parameters are protocols, unless the concrete type is already a framework-free
AppCorevalue type.
Only a RootView constructs a view model, and only from the root:
Previews and tests
A preview variant of the root keeps #Preview blocks one line long and IO-free:
For unit tests, skip the container entirely — construct the view model with stubs directly. If a test needs the whole graph, the type under test has too many dependencies.
When a DI library is warranted
Consider swift-dependencies or Factory when the container has grown past ~30 distinct dependencies and is genuinely hard to read, when you want per-test overrides without threading a container through every initializer, or when you're adopting TCA anyway. Not merely because the app is growing — the plain pattern scales considerably further than people expect, and it costs nothing at build time.
Common pitfalls
- Constructing a view model in a stateless view — it should receive state and closures. See
swiftui-views. - Stashing services in `EnvironmentValues` — Environment is for UI concerns (theme, locale, size class). Business services there are hidden global state with extra steps.
- Forgetting `@MainActor` on a view model — under Swift 6 strict concurrency this surfaces as a data race, usually far from the cause.
- A `static let shared` added "just for this one thing" — it is never just one thing.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/cc-mobile-ios/skills/ios-di/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/dimitriremoiville/cc-mobile/ios-di)