I have this basic scenario where a base class needs to be injected with a Logger class. I am getting kotlin.UninitializedPropertyAccessException: lateinit property logger has not been initialized
in the location mentioned below. What am I missing? (note: constructor injection works but want to avoid adding logger to subclass constructors.
@Singleton
open class BaseRepository(private val userService: UserService) {
@Inject lateinit var logger: Logger
init {
CoroutineScope(Dispatchers.Default).launch {
userService.flow.collectLatest {
logger.setUserId(it?.userId) <-- EXCEPTION FROM HERE
}
}
}
...
}
@Singleton
class HomeRepository @Inject constructor(
private val homeService: HomeService,
userService: UserService,
) : BaseRepository(userService) {
...
}
@Singleton
class LibraryRepository @Inject constructor(
private val libraryService: LibraryService,
userService: UserService,
) : BaseRepository(userService) {
...
}