Hello, we are seeing a weird crash using Koin in a...
# koin
w
Hello, we are seeing a weird crash using Koin in a KMM project 🤔 We call
koin.get(objCObject: type) *as*! T
in Swift and it works, we are calling it in
SceneDelegate
willConnectTo
. When opening the app, all works, putting the app in background, still works, coming back still works. After some time the app in Background, we can see a bunch of crashes in that line on
SceneDelegate
trying to
get
the dependency. The object I’m trying to get in
SceneDelegate
is the
IsAuthenticatedUseCase
(hence I’m putting everything it needs to actually creates its own dependencies - in 🧵).
koin
is created and started in
SceneDelegate
, or the error would be a
nil
if it wasn’t.
Copy code
Non-fatal Exception: InstanceCreationException
Could not create instance for [Singleton:'my.package.common.core.authentication.IsAuthenticatedUseCase']
Sorry for the stacktrace, we are using CrashKiOS to actually be able to see this crash, will post the stacktrace, and definition of dependencies in 🧵
Here are the definitions we have for all the dependencies:
Copy code
single<Settings>(qualifier(SettingsQualifier.ENCRYPTED)) {
        KeychainSettings(KEYCHAIN_SERVICE_NAME)
    }
    single<WebAuthRepository> {
        WebAuthRepositoryImpl(
            settings = get(named(SettingsQualifier.ENCRYPTED)),
        )
    }
    single<MutableStateFlow<Boolean>>(named(AuthenticationQualifier.AUTH)) {
        val isAuthenticated = get<WebAuthRepository>().refreshToken != null
        MutableStateFlow(isAuthenticated)
    }
    single<IsAuthenticatedUseCase> {
        IsAuthenticatedUseCaseImpl(
            isAuthenticatedMutableStateFlow = get(named(AuthenticationQualifier.AUTH)),
        )
    }