Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 2 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 (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-15T11:45:23.000Z (6 months ago)
- Last Synced: 2024-07-30T20:59:13.684Z (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: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwinjectLight
![Build](https://github.com/marekpridal/SwinjectLight/actions/workflows/build.yml/badge.svg) ![Test](https://github.com/marekpridal/SwinjectLight/actions/workflows/test.yml/badge.svg) ![platforms](https://img.shields.io/badge/platform-iOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20macOS%20%7C%20Windows%20%7C%20Ubuntu-333333) [![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) ![GitHub](https://img.shields.io/github/license/marekpridal/SwinjectLight) ![GitHub All Releases](https://img.shields.io/github/downloads/marekpridal/SwinjectLight/total)
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.