SwinjectLight

2.0.1

Lightweight dependency injection framework for Swift (inspired by Swinject)
marekpridal/SwinjectLight

What's New

Release 2.0.1

2025-01-24T14:56:34Z

What's Changed

Full Changelog: 2.0.0...2.0.1

SwinjectLight

Build Test platforms Swift Package Manager compatible GitHub GitHub All Releases

SwinjectLight is framework for lightweight dependency injection which works on any platform supporting Swift. Framework took inspiration from original Swinject implementation but removes some more complex functionality which is usually not necessary.

Installation

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.

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri May 16 2025 09:34:17 GMT-0900 (Hawaii-Aleutian Daylight Time)