uli
02/17/2025, 11:31 AMuli
02/17/2025, 11:31 AM@Module
internal class ManagersModule {
@Single
fun provideOnAppUpdateListener(
onAppUpdateListeners: List<OnAppUpdateListener>
) = onAppUpdateListeners
}
@Single
internal class StartupManagerImpl(
private val localSettingsRepository: LocalSettingsRepository,
private val preferencesMigrationManager: PreferencesMigrationManager,
private val onAppUpdateListeners: Lazy<List<OnAppUpdateListener>>,
) : StartupManager {
If I understand correctly, it will stop working though, as soon as I have another dependency of type List
due to generics erasure and I need to put @Named
annotations on provideOnAppUpdateListener
as well as on the parameter private val onAppUpdateListeners
. And that is where it stops working:
@Module
internal class ManagersModule {
@Single
@Named("List<OnAppUpdateListener>")
fun provideOnAppUpdateListener(
onAppUpdateListeners: List<OnAppUpdateListener>
) = onAppUpdateListeners
}
@Single
internal class StartupManagerImpl(
private val localSettingsRepository: LocalSettingsRepository,
private val preferencesMigrationManager: PreferencesMigrationManager,
@Named("List<OnAppUpdateListener>")
private val onAppUpdateListeners: Lazy<List<OnAppUpdateListener>>,
) : StartupManager {
This gives Caused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'kotlin.Lazy' and qualifier 'List<OnAppUpdateListener>'.
uli
02/17/2025, 12:41 PM@Named
annotation pass module verification tests and the latter one only crashes at runtime.uli
02/17/2025, 1:29 PMarnaud.giuliani
02/18/2025, 4:08 PMarnaud.giuliani
02/18/2025, 4:08 PMLazy<List<OnAppUpdateListener>>
arnaud.giuliani
02/18/2025, 4:09 PMuli
02/18/2025, 4:14 PMarnaud.giuliani
02/18/2025, 4:21 PM• Fixing @Named annotations to work for Lazy?yeah, will see if I can take it in 2.0 else next one
arnaud.giuliani
02/18/2025, 4:21 PMuli
02/18/2025, 4:30 PMseems that you cumulate Lazy & List type 😅Yes, there is a strong use case here, as getAll will potentially instantiate many instances. Our current use case is informing dependencies from our current Android application object about app updates. This happens (obviously) at app start and most the time the depndencies are not needed, as the app most the time has not been updated.Lazy<List<OnAppUpdateListener>>
uli
03/10/2025, 10:22 AM@Single
@Named(type = AppUpdateListener::class)
fun provideLazyAppUpdateListeners(): Lazy<List<AppUpdateListener>> = lazy {
getKoin().getAll<AppUpdateListener>()
}
@Single
class NotifyAppUpdateStartupWork(
@Named(type = AppUpdateListener::class)
private val appUpdateListeners: Lazy<List<AppUpdateListener>>,
)
> Task :app:kspProdApiDebugKotlin
w: [ksp] Koin Configuration Check ...
e: [ksp] --> Missing Definition for property 'appUpdateListeners : kotlin.collections.List' in 'skeleton.model.managers.startup.work.NotifyAppUpdateStartupWork'. Fix your configuration: add definition annotation on the class.
e: Error occurred in KSP, check log for detail
I also tried just providing List<AppUpdateListener>
instead of Lazy<List<OnAppUpdateListener>>
with no success.uli
03/11/2025, 8:09 AMCaused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'java.util.List' and qualifier 'skeleton.model.listeners.AppUpdateListener'
uli
03/11/2025, 8:30 AM@Single
@Named(type = AppUpdateListener::class)
fun provideAppUpdateListeners(): List<AppUpdateListener> = getKoin().getAll<AppUpdateListener>()
@Single
class NotifyAppUpdateStartupWork(
@Provided // ksp Koin Configuration Check (v2.0.0) can't find the declaration
@Named(type = AppUpdateListener::class)
private val onAppUpdateListeners: Lazy<List<AppUpdateListener>>,
)
arnaud.giuliani
03/11/2025, 10:48 AM