DIAttribute

master

Introduce dependency injection attribute (@Inject)
tattn/DIAttribute

DIAttribute

[WIP] DIAttribute introduces dependency injection attribute.

Installation

You can install this framework with Swift Package Manager in Xcode 11.

Feature

Inject protocol values

final class ViewController: UIViewController {
    @Inject(Self.self) var apiClient: APIClientProtocol
    
    ...
}

// Production
DIResolver.register(ViewController.self, keyPath: \.apiClient, value: ProductionAPIClient())

// Test
DIResolver.register(ViewController.self, keyPath: \.apiClient, value: MockAPIClient())

Inject multiple values

struct Environment {
    @Inject(Self.self) var endpoint: URL
    @Inject(Self.self) var timeZone: TimeZone
}

DIResolver.register(Environment.self) {
    Register(URL.self, URL(string: "https://example.com")!)
    Register(TimeZone.self, TimeZone(identifier: "Asia/Tokyo")!)
}

License

DIAttribute is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Oct 17 2024 21:12:02 GMT-0900 (Hawaii-Aleutian Daylight Time)