hmlongco / Resolver

Swift Ultralight Dependency Injection / Service Locator framework
MIT License
2.15k stars 190 forks source link

Cannot resolve dependencies when using XCFramework #117

Closed sahilreddyifit closed 2 years ago

sahilreddyifit commented 3 years ago

If I make an XCFramework and try to inject a dependency from that library into another project I will get this error: Fatal error: RESOLVER: 'Service:NONAME' not resolved. To disambiguate optionals use resolver.optional().

I call Service's register the same why I would if it wasn't an XCFramework but when I switch it to a binary it doesn't work.

Does Resolver work with binary frameworks?

hmlongco commented 3 years ago

I haven't tried it. If you want to make a demo project I can tinker with I can take a look at it.

One thought. Did you try adding the fully scoped name?

register { MyService.Service() }

@Injected var service: MyService.Service
sahilreddyifit commented 3 years ago

Sounds good. Here's the demo

sahilreddyifit commented 3 years ago

@hmlongco were you able to get it working with a binary framework?

HaakonL commented 2 years ago

I am facing this issue as well - did you find a solution? I organise my projects using Xcode Workspace and separate projects for protocols and implementations, and also a separate project for the bootstrapping. Resolver is unable to register protocols and/or implementations from other projects (created as Framework in Xcode Workspace), I only get the error Cannot find 'XXX' in scope when trying to register the dependencies in registerAllServices.

janakagamini commented 2 years ago

My project structure is pretty much the same as @HaakonL's; multiple Framework projects and one App project in the same Workspace. I have the same issue.

I tried using the fully scoped name as suggested here as well, but didn't work

I haven't tried it. If you want to make a demo project I can tinker with I can take a look at it.

One thought. Did you try adding the fully scoped name?

register { MyService.Service() }

@Injected var service: MyService.Service

I have verified that moving all code into the App project works as expected with Resolver.

Any tips?

janakagamini commented 2 years ago

FYI, in my case it was a silly mistake on my part. I had missed use_frameworks! in my Podfile. After adding that, everything works as expected.

For anyone who's interested, I have multiple Frameworks projects and one App project in the same Xcode Workspace. In each Framework I declare:

extension Resolver {
    public static func registerModuleAServices() {
        register { ... }
    }
}

Then, finally in the App project I connect everything together in:

extension Resolver: ResolverRegistering {
    public static func registerAllServices() {
        registerModuleAServices()
        ....
        ....
    }
}

This was a helpful reference. I didn't have to create my own dedicated Framework for Resolver though. Simply adding pod 'Resolver' to all the required targets did the trick.

majie776 commented 2 years ago

这是来自QQ邮箱的自动回复邮件。   邮件已收到

hmlongco commented 2 years ago

FYI, in my case it was a silly mistake on my part. I had missed use_frameworks! in my Podfile. After adding that, everything works as expected.

Glad you found your problem!

Christopher-A commented 2 years ago

@hmlongco Does this mean that Resolver cannot be used as a SPM package; that is to say Resolver.Swift needs to be in my local framework?