The application uses Hilt (built on top of Dagger) for dependency injection. This setup centralizes the creation of complex objects like the database, network clients, and repositories, ensuring they are available throughout the app without manual instantiation. Dependencies are wired at compile time, and the graph is managed automatically based on the lifecycle of Android components (Application, Activity, ViewModel).
Show DI Files
Singleton Module: di/AppSingletonProvides.kt (Contains AppSingletonProvides and AppSingletonBinds)
The dependency graph is defined primarily in AppSingletonProvides.kt, which is split into providers (creating objects) and bindings (mapping interfaces).
Type:@InstallIn(SingletonComponent::class)Purpose: Binds implementation classes to their repository interfaces. This allows the app to depend on abstractions (Interfaces) rather than concrete implementations.
Created via Room.databaseBuilder. Includes a fallback strategy (fallbackToDestructiveMigrationOnDowngrade) to handle development version mismatches safely.
DAOs
Provided directly from the database instance (e.g., db.scrollSessionDao()).
Component
Configuration
OkHttpClient
Includes HttpLoggingInterceptor. Logging is enabled (BODY level) in Debug builds and disabled in Release builds.
Retrofit
Base URL points to the Category Gateway. Uses Gson for JSON parsing.
Pattern
Example
Binding
The app uses abstract @Binds methods. This is more efficient than @Provides as it generates less code.
Injection
Repositories inject DAOs and Dispatchers via their constructors.
Prefer Constructor Injection: Always try to inject dependencies into the constructor (@Inject constructor(...)) rather than using field injection.
Use Qualifiers for Primitives: If injecting a String, Long, or generic interface like CoroutineDispatcher, always use a Qualifier (e.g., @IoDispatcher) to avoid ambiguity.
Avoid Singleton Abuse: Only mark a dependency as @Singleton if it holds state or is expensive to create (like a Database or Network Client). Stateless helpers usually don’t need a scope.
Database Migrations: When modifying the database schema, the migration logic must be added to the AppDatabase builder in AppSingletonProvides.