Swift Package Index


Proof of concept for a dependency injection framework using function builder DSL and PropertyWrappers of swift 5.1


  • The latest stable release is v0.0.1. Released over 1 year ago.
  • The last commit to master was over 1 year ago.

Swift Version Compatibility

  • v0.0.1 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • v0.0.1 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

InjectKit

Proof of concept for a dependency injection framework using function builder DSL and PropertyWrappers of swift 5.1


//Init Dependency Tree
start {
    single(DogType.self) { _ in Dog() }
    factory(Cat.self) { _ in Cat() }
    factory(Cat.self) { _ in Cat() }
    factory(String.self) { _ in "123" }
    single(Database.self) { _ in Database.database() }
    single(Human.self) { Human(dog: $0.resolve(DogType.self)) }
}

// Using by Inject annotation
class Main {
    @Inject private var value: String
    @Inject private var myDog: DogType
    @Inject private var myDog2: DogType
    @Inject private var database: Database
    @Inject private var human: Human

    init() {
        print(value)

        print(myDog.name)
        myDog.run()
        print(myDog.name)
        print(myDog2.name)
        print(human.name)
    }
}


let _ = Main()


Special Thanks to

https://quickbirdstudios.com/blog/swift-dependency-injection-service-locators/

https://blog.vihan.org/swift-function-builders/