Liftric / DIKit

Dependency Injection Framework for Swift, inspired by KOIN.
MIT License
102 stars 17 forks source link

SwiftUI no AppDelegate support #47

Closed sedestrian closed 3 years ago

sedestrian commented 3 years ago

Hi I'm trying to use this library with the new SwiftUI lifecycle that doesn't have an AppDelegate, it seemed ok to initialize it in the "App" class (the one with @main annotation) but when i do, it throws an error "Fatal error: root DependencyContainer is not yet set."

@main
class ChopsticksApp: App {
    @Inject var viewModel: StartupViewModel

    required init() {
        FirebaseApp.configure()
        DependencyContainer.defined(by: modules { .main; .restaurant; .common; .restaurantList })
    }

    var body: some Scene {
        WindowGroup {

        }
    }
}

Also this method of initialization is giving another error

Schermata 2021-07-05 alle 01 35 38

The modules are defined like this

public extension DependencyContainer {
    static var main = module {
        single { FirebaseApp.app() as FirebaseApp? }
    }
}
sedestrian commented 3 years ago

I'm sorry, just noticed that i was requesting to @Inject before initializing the root. The error from the picture still remains though