hmlongco / Factory

A new approach to Container-Based Dependency Injection for Swift and SwiftUI.
MIT License
1.83k stars 115 forks source link

Missing Registeration in Multi Module #160

Closed abdahad1996 closed 11 months ago

abdahad1996 commented 11 months ago

does this library give an error in compile time if let say from the main app i forgot to do the registeration for passing in dependency to a module like the example below cause i am getting a crash at runtime if i don't pass in the dependency

//main App

 extension Container: AutoRegistering {
    public func autoRegister() {
        let styling = PartialViewStyling(isRounded: true, transportTypeImage: Image(uiImage: .add), color: .blue)
      //  transportTypeViewStyling.register { styling }
    }
}

// Module A

// Public Factory
extension Container {
    public var transportTypeViewStyling: Factory<TransportTypeViewStyling?> {   promised()  }
}

public struct PartialView:View {
    @Injected(\.transportTypeViewStyling) private var styling

}
hmlongco commented 11 months ago

promised() is used with optional types and will throw a fatalError in debug mode to let you know that you promised to provide an implementation but apparently did not. In release mode it simply returns nil and lets your optional handling do the job.