I have an android application and I would like to perform dependency injection on a class which is not activity or fragment therefore the applicationContext is not present.
@HiltAndroidApp
class App: Application {
@Inject
lateinit var analytics: Analytics
override fun onCreate() {
super.onCreate()
// other details
}
}
My AppModule
@Module
@InstallIn(ApplicationComponent::class)
abstract class AppModule() {
companion object {
@Provide
@Singleton
fun provideSomeClass(): SomeClass = SomeClass()
}
}
If I try to inject SomeClass in a activity it works fine but not on a non activity class it fails with an error Object is not initialized.
class Consumer {
@lateinit var SomeClass someClass;
}
Can someone point what I am doing wrong?