hmlongco / Resolver

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

registerAllServices method is not called in the main project #91

Closed sanyesz123 closed 3 years ago

sanyesz123 commented 3 years ago

Setup

I have an iOS application target which uses Resolver 1.4.0. I also have a cocoa touch framework target using Resolver too. The framework is embedded in the main application's bundle. The Resolver framework is pulled into the project via Cocoapods, and it is shared through an abstract target in the Podfile.

Resolver registrations

Both targets have their own Resolver extensions for registering the dependencies.

import Resolver

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

The problem

The compiler can compile both targets, the application's bundle is created successfully and looks good. A strange behaviour happens only on iOS 12.X simulators (on real devices, and on simulators with later iOS versions everything is working fine): when the application is started the registerAllServices static method is called from the framework and not from the main application target (even if the framework is not imported in the code), so the application won't register its classes and it crashes during the first injection.

References related to problem:

Sample project

ResolverExample.zip

Question

Do you have any options / ideas how to handle this case?

sanyesz123 commented 3 years ago

Update: seems the problem is present on some iOS 12.x real devices too.

hmlongco commented 3 years ago

I'm not sure if this covers everything, but the following project repository demonstrates using Resolver across frameworks and in the main application.

https://github.com/hmlongco/ResolverFrameworksTest

This may not be an exact parallel, but it may help you get to where you need to be.