marekpridal/swinjectlight
SwinjectLight is framework for lightweight dependency injection which works on any platform supporting Swift. Framework took inspiration from original [Swinject](https://github.com/Swinject/Swinject) implementation but removes some more complex functionality which is usually not
Installation
Swift Package Manager
To add a package dependency to your Xcode project, select File > Add Package Dependency and https://github.com/marekpridal/SwinjectLight.
Alternatively in Package.swift add the following
// swift-tools-version:5.10
import PackageDescription
let package = Package(
name: "SwinjectLightExample",
dependencies: [
.package(url: "https://github.com/marekpridal/SwinjectLight", from: "1.0.0")
],
targets: [
.target(name: "SwinjectLightExample", dependencies: ["SwinjectLight"])
]
)Usage
import SwinjectLight
// Create container
let container = Container()
// Register singleton dependency
container.register(Session.self) { r in
DefaultSession.shared
}
// Register instance based dependency
container.register(Api.self) { r in
Networking(session: r.resolve(Session.self))
}
// Resolve dependency
let api = container.resolve(Api.self)You can also check out demo project in repo for further details about usage.
Package Metadata
Repository: marekpridal/swinjectlight
Default branch: main
README: README.md