https://kotlinlang.org logo
#koin
Title
# koin
b

bastienC

03/09/2023, 10:57 AM
Hi, just trying to “handle” generics types with koin (https://insert-koin.io/docs/reference/koin-core/definitions#dealing-with-generics), I tried to create “multiple” modules (one for each generic typed class to avoid overriding), but don’t seems to work... I prefer to avoid “named” because it’s touchy for the entire codebase, and not sure everyone will use it when needed... Any idea ?
Copy code
interface StoreListDataSource<T> {

}

class DataSourceOne : com.moten.android.di.StoreListDataSource<String> {

}

class DataSourceTwo : com.moten.android.di.StoreListDataSource<String> {

}

val dataSourceOneModule = module {
    single { DataSourceOne() }
}

val dataSourceTwoModule = module {
    single { DataSourceTwo() }
}

startKoin {
    androidLogger()
    androidContext(this@MotenApplication)
    modules(
        dataSourceOneModule,
        dataSourceTwoModule
    )
}
Injected value will be the last “built”, ie. DataSourceTwo() impl