https://github.com/tattn/diattribute
Introduce dependency injection attribute (@Inject)
https://github.com/tattn/diattribute
dependency-injection ios swift
Last synced: about 1 year ago
JSON representation
Introduce dependency injection attribute (@Inject)
- Host: GitHub
- URL: https://github.com/tattn/diattribute
- Owner: tattn
- Created: 2019-06-15T11:44:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-03T16:50:02.000Z (almost 7 years ago)
- Last Synced: 2025-04-05T05:01:38.910Z (about 1 year ago)
- Topics: dependency-injection, ios, swift
- Language: Swift
- Homepage:
- Size: 5.86 KB
- Stars: 44
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
DIAttribute
===
[WIP] DIAttribute introduces dependency injection attribute.
# Installation
You can install this framework with Swift Package Manager in Xcode 11.
# Feature
## Inject protocol values
```swift
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
```swift
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.