https://github.com/eneskaraosman/swinjector
Simple dependency injection package inspired by get_it Flutter package
https://github.com/eneskaraosman/swinjector
dependency-injection getit injection ios swift swiftui
Last synced: 12 months ago
JSON representation
Simple dependency injection package inspired by get_it Flutter package
- Host: GitHub
- URL: https://github.com/eneskaraosman/swinjector
- Owner: EnesKaraosman
- Created: 2024-01-07T06:34:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T07:13:36.000Z (over 2 years ago)
- Last Synced: 2025-05-13T21:40:58.541Z (about 1 year ago)
- Topics: dependency-injection, getit, injection, ios, swift, swiftui
- Language: Swift
- Homepage:
- Size: 28.3 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swinjector
[](https://codecov.io/gh/EnesKaraosman/Swinjector)
TODO
- [ ] Easify registering and resolving dependency syntax?
- [ ] Support registering multiple instance of the same type?
- [x] Add code documentation
- [x] Add unit test execution github action
- [x] Integrate code coverage app (codecov)
- [x] Unit test code coverage %100
## Register dependencies
```swift
// Lazy singleton is created when you access it
GetIt.I.registerLazySingleton(TestProtocol.self) { TestClass() }
// Singleton is already created by you
GetIt.I.registerSingleton(TestProtocol.self, instance: TestClass())
// New instance is created every time you access it
GetIt.I.registerFactory(TestProtocol.self) { TestClass() }
```
## Access dependencies
```swift
if let instance = GetIt.I.resolve(TestProtocol.self) {}
// More swifty syntax
if let instance = GetIt.I(TestProtocol.self) {}
// Access by annotation
@Injected(TestProtocol.self) var instance
instance().foo()
```
## Check if dependency is registered & unregister
```swift
let isRegistered = GetIt.I.isRegistered(TestProtocol.self)
GetIt.I.unregister(TestProtocol.self)
```