- Use current
Injector.shared
or create newInjector
- Register dependencies using
Injector.add()
- Use
@Injected
wrapper
struct Engine {
let power: Float
}
struct Car {
@Injected var engine: Engine
}
let container = Injector()
container.add({ Engine(power: 88.7) as Engine })
container.add({ Car() })
Injector.shared = container
let car: Car = container.resolve()
car.engine.power // 88.7
For singletons you can use Scope
:
container.add(scope: .singletone, { Engine(power: 88.7) as Engine })
This library is only available as an SPM package
.package(url: "https://github.com/KirillSaltykov/Injected.git", .upToNextMinor(from: "0.1.0"))