How to Inject field in an object module that provides - Hilt Android

Viewed 34

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.

0 Answers
Related