Skillshub ios-dependency-injection
Standards for Protocol-based DI, Property Wrappers, and Factory/Needle. Use when configuring dependency injection or factory patterns in iOS. (triggers: **/*.swift, @Injected, Resolver, Container, Swinject, register, resolve)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/ios-dependency-injection" ~/.claude/skills/comeonoliver-skillshub-ios-dependency-injection && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/ios-dependency-injection/SKILL.mdsource content
iOS Dependency Injection Standards
Priority: P0
Implementation Guidelines
Protocol-Based DI (Manual)
- Initializer Injection: Preferred method. Pass dependencies through
.init - Abstractions: Inject protocols instead of concrete classes to facilitate testing (Mocks/Stubs).
Modern Property Wrappers (Factory/Resolver)
- Factory: Use the
library for lightweight, type-safe navigation-friendly DI.Factory - Swinject: Use for enterprise-grade container-based DI in large modular projects.
- Injected: Use
property wrappers for cleaner syntax in ViewModels.@Injected
Scoping
- Singleton: Use for app-wide services (Auth, Network, Database).
- Unique/Transient: Default for ViewModels and temporary workers.
- Graph/Cached: Use for shared data within a specific feature flow (Coordinator scope).
Anti-Patterns
- No global singleton access everywhere: Inject service via initializer.
- No Resolver.resolve() inside logic: Pass dependency via constructor.
- No direct class instantiation: Depend on protocols for testability.