Swiftpack.co - Package - KirillSaltykov/Injected

Inejcted

codebeat badge

How to use?

  1. Use current Injector.shared or create new Injector
  2. Register dependencies using Injector.add()
  3. Use @Injected wrapper

Example

struct Engine {
    let power: Float
}

struct Car {
    @Injected var engine: Engine
}

let container = Injector()
container.add({ Engine(power: 88.7) as Engine })
container.add({ Car() })

Injector.shared = container

let car: Car = container.resolve()
car.engine.power // 88.7

For singletons you can use Scope:

container.add(scope: .singletone, { Engine(power: 88.7) as Engine })

How to install

This library is only available as an SPM package

.package(url: "https://github.com/KirillSaltykov/Injected.git", .upToNextMinor(from: "0.1.0"))

Github

link
Stars: 2

Dependencies

Used By

Total: 0

Releases

Fixed init - 2020-05-18 16:41:12

Added public init.

First release - 2020-05-18 16:23:38

This is not a production-grade library, so use it at your own risk.