hmlongco / Factory

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

SwiftUI previews with multiple modules #200

Open callo90 opened 2 months ago

callo90 commented 2 months ago

Hello,

I've been facing problems with the SwiftUI preview, I have an app that runs clean architecture in multiple modules, SwiftUI preview doesn't work properly running the app scheme, so I had to run specifically the UI module, this works properly in most of the cases but sometimes injecting with @LazyInjected doesn't solve the issue and get the error resetAndTriggerFatalError("\(T.self) was not registered", #file, #line), I tried changing the build configuration to release for that module but for some reason the preview didn't work at all.

    public func promised<T>(key: StaticString = #function) -> Factory<T?>  {
        Factory<T?>(self, key: key) {
            #if DEBUG
            if self.manager.promiseTriggersError {
                resetAndTriggerFatalError("\(T.self) was not registered", #file, #line)
            } else {
                return nil
            }
            #else
            nil
            #endif
        }
    }
hmlongco commented 2 months ago

Would probably need a minimum viable project to try and diagnose this.

callo90 commented 1 month ago

I'll prepare a quick demo.