Skip to content

Basic Dependency Injection library using property wrappers

Notifications You must be signed in to change notification settings

KirillSaltykov/Injected

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"))