79184682

Date: 2024-11-13 11:33:41
Score: 1.5
Natty:
Report link

In case anyone stumbles upon this, i've finally understood my mistake: turns out that, while my @ActivityContext injection into my AuthModule was OK, I was still trying to inject the module in ViewModel, which means it would indirectly hold a reference to the Activity, and thus Hilt wouldn't allow me to inject it.

My somewhat ugly solution was to just inject my module into the Activity itself, since I have only one, and then pass the module as a reference down to other composables, and THEN finally pass it down to the ViewModel so it could make its things

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
  @Inject lateinit  var authService: AuthService
  // ....
  AuthScreen(authService = authService, ...)
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ActivityContext
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: KaduCmK