A very Simple Dependency Injector to be used with SwiftUI
To install ShuInjector
using Swift Package Manager, add
.package(name: "ShuInjector", url: "https://github.com/SimpleBoilerplates/ShuInjector", from: "1.0.0"),"
to your Package.swift, then follow the integration tutorial here.
Coming soon
import ShuInjector
First define your assembler, like HTTP assembler or router etc
final class HTTPAssembler: ShuiAssembler {
func assemble() {
let provider = MoyaProvider<MultiTarget>(callbackQueue: DispatchQueue.main)
ShuInjector.register(provider)
ShuInjector.register(HttpManager())
}
}
Now Assemble it anywhere maintaining hiearchy, before their usage
ShuInjectorAssembler.assemble(assemblers: [
HTTPAssembler()
])
Now can you use that provider from any class that will be initialized after assembling. As example
class HttpManager {
@Inject var provider: MoyaProvider<MultiTarget>
}
This HTTP manager now can be accessed from any class that will be initialized later
class AuthRepository {
@Inject var httpManager: HttpManager
}
And so on.
Architecture should be like you can define Several ShuiAssembler for different purposes, different features, HTTPAssembler should be defined on Shared level, there can be other ShuiAssembler for different purposes, like AppAssembler, that will handle Router, User Token etc.
Follow and contact me on Twitter or LinkedIn. If you find an issue, just open a ticket. Pull requests are warmly welcome as well.
If you want fix anything or improve or add any new feature you are very much welcome.
Cachy is released under the MIT license. See LICENSE for details.