https://github.com/marekpridal/SwinjectLight
Lightweight dependency injection framework for Swift (inspired by Swinject)
https://github.com/marekpridal/SwinjectLight
apple dependencies dependency dependency-injection ios ipados linux macos swift swift-package-manager tvos ubuntu visionos watchos windows
Last synced: 4 months ago
JSON representation
Lightweight dependency injection framework for Swift (inspired by Swinject)
- Host: GitHub
- URL: https://github.com/marekpridal/SwinjectLight
- Owner: marekpridal
- License: mit
- Created: 2024-06-06T11:39:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-24T14:55:56.000Z (6 months ago)
- Last Synced: 2025-02-27T09:09:39.911Z (5 months ago)
- Topics: apple, dependencies, dependency, dependency-injection, ios, ipados, linux, macos, swift, swift-package-manager, tvos, ubuntu, visionos, watchos, windows
- Language: Swift
- Homepage:
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwinjectLight
   [](https://github.com/apple/swift-package-manager)  
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 necessary.
## Installation
### [Swift Package Manager](https://github.com/apple/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
// swift-tools-version:5.10import 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
```swift
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](DIDemoApp) for further details about usage.