Kevin ABRIOUX
Kevin ABRIOUX

Reputation: 17735

How to access Hilt module in Application class

I have an application class MainApplication

enter image description here

I need to access to a Hilt module in this class:

enter image description here

How can I achieve this ?

Upvotes: 1

Views: 1959

Answers (1)

gowtham6672
gowtham6672

Reputation: 1068

@HiltAndroidApp
class MainApplication : MultiDexApplication() {

    @Inject
    lateinit var hceRepository: HceRepository //new

    override fun onCreate() {
        // Try to call anything of hceRepository in here.
    }
}

Do the field injection in the Application class. This should be enough

Upvotes: 5

Related Questions