2

I have two classes on my android project: one is an object module and the other one is providing functions to be returned in the object module.

Class 1: APIModule

@Module
@InstallIn(SingletonComponent::class)
object APIModule {
    @Inject
    lateinit var db: FirestoreDB

    @Singleton
    @SandalItems
    @Provides
    fun provideCustomItems() = db.getCustomItems("sandals")

    @Singleton
    @ShoeItems
    @Provides
    fun provideCustomItems() = db.getCustomItems("shoes")
    ...
}

Class 2: FirestoreDB

@Singleton
class FirestoreDB {
    @Inject
    lateinit var myAPI: MyAPI
    private val db = Firebase.firestore

    ...

    // This getter method that will return a firestore Query
    fun getCustomItems(type: String) : Query { ... }
}

After building, APIModule class throws error: dagger does not support injection into kotlin objects

Any possible ways workaround here? I'm pretty new to android development and dependency injection.

Firate
  • 105
  • 5
  • 1
    Since the solution has absolutely nothing to do with the dupe target: provide the db as a parameter in the @Provides methods, not as a field in the module. – Nitrodon Jul 14 '22 at 17:09
  • @Nitrodon this was what I did, thanks anyway! I dont know how to remove the provided solution, the answer provided might mislead people to different approach. – Firate Jul 15 '22 at 14:06

0 Answers0