Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 2.02 KB

README.md

File metadata and controls

52 lines (37 loc) · 2.02 KB

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.