Hi, I want to create 2 concrete clases, that implement an interface that has generic parameters
interface BaseDataToDomainMapper<out DomainModel, in DataModel> {
fun toItem(item: DataModel): DomainModel
fun toItems(dataList: List<DataModel>): List<DomainModel> { return emptyList() }
}
I want go provide 2 difference mappers that implement that interface, but koin do not let me
use generics to provide.
How can I do it to provide a MapperA, MapperB that implement BaseDataToDomainMapper ?
single(named(“GrowerEntityWithProductLocationDomainMapper”)){
GrowerEntityWithProductLocationDomainMapper( get())
}
Should I use qualifiers named ? should I use the interface after the single ??
single<BaseDataToDomainMapper<GrowerEntityWithProductLocationItem, ProductLocationDao.GrowerEntityWithProductLocation>>(named(“GrowerEntityWithProductLocationDomainMapper”)){
GrowerEntityWithProductLocationDomainMapper( get())
}
Yes, I would use named items. Here is an example from my code:
val coroutines = module {
single (named(“Background”)) { Dispatchers.Default}
single (named(“IO”)) { Dispatchers.IO}
single (named(“UI”)) { Dispatchers.Main}
}
Then you can inject them with that named value you want