I'm trying to provide 2 Firebase CollectionReference objects with Dagger2
@Provides
@Singleton
@FirebaseSongsDatabaseReferenceNamed
internal fun provideUserSongsDatabaseSnapshotRef(dbRef: FirebaseFirestore): CollectionReference =
dbRef.collection("users-songs")
@Provides
@Singleton
@FirebaseUserListDatabaseReferenceNamed
internal fun provideUsersListDatabaseRef(dbRef: FirebaseFirestore): CollectionReference =
dbRef.collection("users-list")
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
annotation class FirebaseSongsDatabaseReferenceNamed(val value: String = "songs-by-user-data-reference")
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
annotation class FirebaseUserListDatabaseReferenceNamed(val value: String = "users-list-reference")
But when I compile, Dagger fails with duplicate bindings error.
[Dagger/DuplicateBindings] com.google.firebase.firestore.CollectionReference is bound multiple times:
@Provides @Singleton @org.jetbrains.annotations.NotNull com.google.firebase.firestore.CollectionReference network.NetworkModule.provideUserSongsDatabaseSnapshotRef$network_debug(com.google.firebase.firestore.FirebaseFirestore)
@Provides @Singleton @org.jetbrains.annotations.NotNull com.google.firebase.firestore.CollectionReference network.NetworkModule.provideUsersListDatabaseRef$network_debug(com.google.firebase.firestore.FirebaseFirestore)
My app is divided into a few modules. I tried adding similar code in the main module and error is not appearing there. It happens only in submodule. Here is working code from the main module.
@Provides
@FirebaseLoginIntentNamed
fun provideFirebaseUILoginIntent(): Intent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(firebaseLoginProviders)
.build()
@Provides
@TestNamed
fun provideTestIntent(str: String): Intent = Intent(str)
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
annotation class FirebaseLoginIntentNamed(val value: String = "firebase-login-intent")
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
annotation class TestNamed(val value: String = "intent-test")