Dagger 2.32
I am getting the following error when I try provide the implemenation for the interface DomainMapper<PlayerDataEntity, List<PlayerModel>>
error: [Dagger/MissingBinding] me.androidbox.data.mappers.DomainMapper<? super me.androidbox.data.entities.PlayerDataEntity,? extends java.util.List<me.androidbox.domain.models.PlayerModel>> cannot be provided without an @Provides-annotated method.
public abstract interface ApplicationComponent {
^
me.androidbox.data.mappers.DomainMapper<? super me.androidbox.data.entities.PlayerDataEntity,? extends java.util.List<me.androidbox.domain.models.PlayerModel>> is injected at
me.androidbox.data.requests.imp.RequestPlayersImp(…, domainMapper)
me.androidbox.data.requests.imp.RequestPlayersImp is requested at
me.androidbox.app.application.ApplicationComponent.requestPlayersImp()
Following classes:
class RequestPlayersImp @Inject constructor(
private val footballServices: FootballServices,
private val domainMapper: DomainMapper<PlayerDataEntity, List<PlayerModel>>
) : PlayersInteractor {
}
class DomainMapperImp @Inject constructor(): DomainMapper<PlayerDataEntity, List<PlayerModel>> {
}
@Module
interface PlayerModule {
@Binds
fun provideRequestPlayersImp(requestPlayersImp: RequestPlayersImp): PlayersInteractor
@Binds
fun provideFootballServices(mockFootballServices: MockFootballServices): FootballServices
@Binds
fun provideDomainMapper(domainMapperImp: DomainMapperImp): DomainMapper<PlayerDataEntity, List<PlayerModel>>
}
However, I can solve the issue by creating a new Interface:
interface DomainMapperEntityToDomain : DomainMapper<PlayerDataEntity, List<PlayerModel>>
And using that as below. Everything compiles ok
class RequestPlayersImp @Inject constructor(
private val footballServices: FootballServices,
private val domainMapper: DomainMapperEntityToDomain
) : PlayersInteractor {
}
class DomainMapperImp @Inject constructor(): DomainMapperEntityToDomain {
}
@Binds
fun provideDomainMapper(domainMapperImp: DomainMapperImp): DomainMapperEntityToDomain
My questions is why can't I use the following interface:
DomainMapper<PlayerDataEntity, List<PlayerModel>>
Many thanks for any advice,
data classes just incase they are important
@JsonClass(generateAdapter = true)
class PlayerDataEntity(
val data: List<PlayerEntity>
)
data class PlayerModel(
val playerId: Int,
val firstname: String,
val lastname: String,
val birthday: String,
val age: Int,
val weight: Int,
val height: Int,
)
Use this:
DomainMapper<@JvmSuppressWildcards PlayerDataEntity, @JvmSuppressWildcards List< @JvmSuppressWildcards PlayerModel>>
instead of:
DomainMapper<PlayerDataEntity, List<PlayerModel>>
you can find more details about it in this link