hmlongco / Resolver

Swift Ultralight Dependency Injection / Service Locator framework
MIT License
2.14k stars 188 forks source link

RESOLVER: 'OnboardingNavigatorProtocol:NONAME' not resolved. To disambiguate optionals use resolver.optional(). #118

Closed ahmadmssm closed 2 years ago

ahmadmssm commented 3 years ago

I'm getting this error when I try to resolve an object that conforms to multiple protocols.

Here is how I'm trying to resolve it: let navigator: OnboardingNavigatorProtocol = Resolver.resolve() And here is how I provide the dependency:

extension Resolver {
    static func registerNavigationModules() {
        register { OnboardingNavigator() }
            .implements(OnboardingNavigatorProtocol.self)
            .implements(UIApplicationDelegate.self)
    }
}

But if I did this, It will work let navigator: OnboardingNavigatorProtocol = Resolver.resolve(OnboardingNavigator.self) Even if I removed .implements(OnboardingNavigatorProtocol.self)

hmlongco commented 3 years ago

You have something else going on. Multiple protocols with implements is a standard test case.

    func testMultipeProtocolsWithImplements() {
        resolver.register { XYZCombinedService() }
            .implements(XYZFetching.self)
            .implements(XYZUpdating.self)

        let service: XYZCombinedService? = resolver.optional()
        XCTAssertNotNil(service)
        XCTAssert(service?.name == "XYZCombinedService")

        let fetcher: XYZFetching? = resolver.optional()
        XCTAssertNotNil(fetcher)
        XCTAssert(fetcher?.name == "XYZCombinedService")

        let updater: XYZUpdating? = resolver.optional()
        XCTAssertNotNil(updater)
        XCTAssert(updater?.name == "XYZCombinedService")
    }