Swiftpack.co - KuroiDOC/DOCtor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by KuroiDOC.
KuroiDOC/DOCtor 1.0.0
Simple lightweight dependency injector. Works with Swift 5.2 and higher.
⭐️ 0
🕓 41 weeks ago
.package(url: "https://github.com/KuroiDOC/DOCtor.git", from: "1.0.0")

DOCtor

Simple lightweight dependency injector. Works with Swift 5.2 and higher.

Usage examples:

struct Foo {
    @Injectable var bar: Bar
    @Injectable(name: "Bar2") var bar2: Bar
}

struct Bar {
    var msg: String
}

class Singleton {
    var msg: String

    init(msg: String) {
        self.msg = msg
    }
}

Container.main.register(Factory { Foo() })
Container.main.register(Factory { Bar(msg: "HI") })
Container.main.register(Factory { Bar(msg: "BYE") }, name: "Bar2")

let foo = Container.main.resolve(Foo.self)

Container.main.register(Single { Singleton(msg: "Singleton") })
Container.main.register(Factory { Singleton(msg: "NotASingleton") }, name: "FakeSingleton")

let singleton = Container.main.resolve(Singleton.self)

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics