Minimalist dependency injection mechanism written in pure Swift.
Support any first party Swift platfom. [ iOS / iPadOS / watchOS / macOS / Linux ]
Well tested. Used in production across the Infomaniak iOS Apps.
Property wrapper based with @LazyInjectService
and @InjectService
.
Optimised to work well with SwiftUI Views.
@(Lazy)InjectService
will not re-resolve, when used as a property, on a View
redraw.Early on in the lifecycle of your app, you want to write something like this :
import InfomaniakDI
[…]
let factory = Factory(type: SomeService.self) { _, _ in
SomeService()
}
do {
try SimpleResolver.sharedResolver.store(factory: factory)
}
catch {
FatalError("unexpected DI error \(error)")
}
later on, when you want to resolve a service use the property wrapper like so:
@InjectService var injected: SomeService
Injection will be performed at the init time of the owner of the property.
Use @LazyInjectService
for resolution at first use of the wrapped property. Prefer @LazyInjectService
when used as a property.
Checkout ITSimpleReslover.swift
for more advanced examples.
This package is available under the permissive ApacheV2 licence for you to enjoy.
link |
Stars: 4 |
Last commit: 1 week ago |
Full Changelog: https://github.com/Infomaniak/swift-dependency-injection/compare/2.0.0...2.0.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics