Managing Dependency Scopes per Logged-in User with Hilt Custom Component

·2026.11.11 15:41

Key point

Hilt Custom Component regenerates the dependency tree upon login state changes to manage object lifecycles per user.

1 / 7

Details

  • Hilt Custom Component must be located in the hierarchy below SingletonComponent and cannot be inserted between existing Hilt components
  • The structure is implemented to regenerate AuthUserComponent when the logged-in user changes, injecting Repository and DataSource objects specific to that user
  • Access Custom Component via EntryPoint, and use EntryPointAccessor to ensure type safety
  • AuthUserComponentManager subscribes to UserAuthSession to automatically regenerate the component when login/logout events occur
  • Using Custom Component has the drawbacks of increased dependency graph complexity and difficulty integrating with external libraries
  • The sample app is available in the HiltCustomComponentSample repository on GitHub

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.