Hi, i have been trying to provide different implementation
```
interface ICurrentUserRepo
fun get(): output
fun update(input: input)
fun delete(input: input)
fun insert(input: input)
}```
and i'm providing two implementation of the interface by dagger
```@Dao
interface LocalUserRepo : ICurrentUserRepo
@Query("SELECT * FROM CURRENT_USER")
override fun get(): Flowable<CurrentUser>
@Delete
override fun delete(input: CurrentUser)
@Insert
override fun insert(input: CurrentUser)
@Update
override fun update(input: CurrentUser)
}```
second one
```class RemoteUserRepo(val remoteUsersDB: DatabaseReference) : ICurrentUserRepo
override fun update(input: Params) {
TODO("not implemented for now, should update user info in database")
}
override fun get() {
TODO("not implemented for now, should return user from database")
}
override fun delete(input: Params) {
TODO("not implemented for now, should delete user from database")
}
override fun insert(input: Params) {
}
open class Params(val user: CurrentUser, val observer: DisposableCompletableObserver)
}```
This my module
```@Provides
@Singleton
@LocalUserDb
internal fun provideLocalUserDb(database: UserDatabase) : ICurrentUserRepo
= database.CurrentUserDao()
@Provides
@Singleton
@RemoteUserDb
internal fun provideRemoteUserDb(@FirebaseUsersTable usersTable: DatabaseReference): ICurrentUserRepo<RemoteUserRepo.Params, Unit>
= RemoteUserRepo(usersTable)```
[4:24]
why i cant provide different type of interface implementation with dagger ?
i get this error
/home/darel/StudioProjects/XXX/app/build/tmp/kapt3/stubs/debug/com/xxx/xxxx/di/components/XXXAppComponent.java:6: error: [com.XXXX.XXX.di.components.AuthenticationComponent.inject(com.XXX.XXX.authentication.view.AuthActivity)] @com.XXX.XXX.di.LocalUserDb com.XXX.XXX.data.ICurrentUserRepo super com.XXX.XXX.domain.Entities.CurrentUser,? extends io.reactivex.Flowable
public abstract interface SociallyAppComponent {
e: ^
e: @com.XXX.XXX.di.LocalUserDb com.XXX.XXX.data.ICurrentUserRepo super com.XXX.XXX.domain.Entities.CurrentUser,? extends io.reactivex.Flowable
e: com.XXX.XXX.di.modules.AuthenticationModule.provideAuthPresenter(…, localDb, …)
e: com.XXX.XXX.authentication.presenters.AuthPresenter is injected at
e: com.XXX.XXX.authentication.view.AuthActivity.presenter
e: com.XXX.XXX.authentication.view.AuthActivity is injected at
e: com.XXX.XXX.di.components.AuthenticationComponent.inject(authActivity)
Can we do this with dagger ? or do we need to add any stuff or it's a bug ?
I think you are having wildcard/kotlin issue on generics. You need to add @JvmSuppressWildcards when injecting your ICurrentUserRepo in AuthActivity. Here's an example from Stackoverflow https://stackoverflow.com/questions/43141740/dagger-2-multibindings-with-kotlin
Here's another example:
@Inject constructor(val jobs: @JvmSuppressWildcards Map<String, Provider<JobTime>>)
Â
THANKS A LOT! that was the issue...
Most helpful comment
I think you are having wildcard/kotlin issue on generics. You need to add @JvmSuppressWildcards when injecting your ICurrentUserRepo in AuthActivity. Here's an example from Stackoverflow https://stackoverflow.com/questions/43141740/dagger-2-multibindings-with-kotlin
Here's another example:
@Inject constructor(val jobs: @JvmSuppressWildcards Map<String, Provider<JobTime>>) Â