I want to implement authentication in my application, so I want to get the current logged user in the application class, I am following GithubBrowserSample to develop my application, but I am very new to dagger injection and I am a little lost in how to inject my authRepository to my application class.
class App : Application(), HasActivityInjector {
@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
AppInjector.init(this)
}
override fun activityInjector() = dispatchingAndroidInjector
}
I tried adding something like
@Inject
lateinit var authRepository: AuthRepository
in the application class and in the AppModule
//I already have functions that provide everything the repository needs
@Singleton
@Provides
fun provideAuthRepository(
appExecutors: AppExecutors,
db: AppDatabase,
trainersService: TrainersService,
sessionDao: SessionDao,
tokenInterceptor: TokenInterceptor
): AuthRepository {
return AuthRepository(
appExecutors,
db,
trainersService,
sessionDao,
tokenInterceptor
)
}
but it throws Uninitialized Property Access Exception
Hope you can help me to achive this following the github sample approach.