Here’s a simple quick-start using protocol-based initializer injection first, then Factory for wiring: ```swift import UIKit import Factory protocol AnalyticsServiceProtocol { func logEvent(name: String) } final class AnalyticsService: AnalyticsServiceProtocol { func logEvent(name: String) { print("Logged: \(name)") } } final class HomeViewModel { private let analytics: AnalyticsServiceProtocol init(analytics: AnalyticsServiceProtocol) { self.analytics = analytics } func screenOpened() { anal...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-dependency-injection --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Ios Dependency Injection?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-dependency-injection-e20caa45)More formats (shields.io, HTML) on the badges page.
Here’s a simple quick-start using protocol-based initializer injection first, then Factory for wiring:
```swift
import UIKit
import Factory
protocol AnalyticsServiceProtocol {
func logEvent(name: String)
}
final class AnalyticsService: AnalyticsServiceProtocol {
func logEvent(name: String) {
print("Logged: \(name)")
}
}
final class HomeViewModel {
private let analytics: AnalyticsServiceProtocol
init(analytics: AnalyticsServiceProtocol) {
self.analytics = analytics
}
func screenOpened() {
analytics.logEvent(name: "home_opened")
}
}
extension Container {
var analyticsService: Factory<AnalyticsServiceProtocol> {
self { AnalyticsService() }.singleton
}
var homeViewModel: Factory<HomeViewModel> {
self { HomeViewModel(analytics: self.analyticsService()) }
}
}
final class HomeViewController: UIViewController {
@Injected(\.homeViewModel) private var viewModel
override func viewDidLoad() {
super.viewDidLoad()
viewModel.screenOpened()
}
}
```
Why this setup:
- Use initializer injection as the default.
- Depend on protocols, not concrete classes.
- Keep singleton scope for app-wide services like analytics.
- Avoid resolving dependencies inline inside business logic.
Is this your skill, or is something wrong with this listing? . Author removals are honored within 72 hours.
No comments yet. Be the first to comment!