目录
目录README.md

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.

关于
34.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号