Skip to content

Dagger DI #38

Description

@AlexisTercero55

Dagger DI

1. Dagger Dependency Injection: Component Dependency & Scoped Orchestration

We will implement a Pure Dagger architecture using Component Dependencies to maintain strict module encapsulation and explicit lifecycle control.

1.1 Multi-Module Component Topology

To preserve the "Clean Architecture" boundaries, we avoid Subcomponents and instead use Component Dependencies.

  • CoreComponent (in :core:data):
    • Scope: @Singleton.
    • Exposure: Explicitly exposes AuthRepository, SessionManager, and Json infrastructure.
    • Responsibility: Houses stateless or global-state services.
  • UserComponent (in :app or :core:data) [NEW]:
    • Scope: @UserScope.
    • Dependency: CoreComponent.
    • Lifetime: Created upon successful login; invalidated immediately upon logout.
    • Responsibility: Hosts session-sensitive interactors and transient state for flows like Loan Wizards.
  • FeatureComponents (in :features:*):
    • Dependency: CoreComponent (and UserComponent for authenticated features).
    • Responsibility: Provides feature-specific ViewModels via multibinding.

1.2 Scoped Component Management

We will implement a ComponentManager at the :app level to orchestrate the lifecycle of the UserComponent. This ensures that when a user logs out, the entire session-scoped graph is garbage collected, fulfilling fintech requirements for Secure Session Isolation.

1.3 ViewModel Multibinding & Factory

  • Implement a DaggerViewModelFactory in :core:ui that leverages a Map<Class<? extends ViewModel>, Provider<ViewModel>>.
  • Use @IntoMap and @ViewModelKey in feature modules to decouple the UI from the instantiation of business logic.

Phase 1: Environment & Core DI Infrastructure

  1. Dependency Injection & Firebase Setup: Update libs.versions.toml with Dagger 2, Firebase BOM, and DataStore dependencies. Apply plugins and dependencies to all module build.gradle.kts files.
  2. Annotation Definition: Create @UserScope and @ViewModelKey in :core:domain or :core:ui.
  3. Core Data Module: Create CoreModule and CoreComponent in :core:data to provide Json and basic infrastructure.
  4. ViewModel Factory: Implement DaggerViewModelFactory in :core:ui.

Phase 3: Feature & App Layer Integration

  1. Feature Multibinding: Annotate LoginViewModel and HomeViewModel with @Inject and register them in their respective Dagger modules using @IntoMap.
  2. UserComponent Orchestration: Implement the ComponentManager in :app to manage the lifecycle of the @UserScope graph.
  3. Application & Activity Wiring: Initialize the Dagger graph in RhoApplication.kt and trigger injection in MainActivity.kt.

Rho.Studio® - Engineering Department - Contact alexis.tercero@rho.studio

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CoreRho Studio UI app codebaseDagger DIDagger2 Dependency injection

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions