Refactor RecommendationService to use Hilt dependency injection
Summary
Refactor RecommendationService singleton to use Hilt for better testability and maintainability
Background
Code review feedback from !7 (merged) suggested moving from manual singleton pattern to Hilt dependency injection for improved testability and cleaner architecture.
Requirements
- Add Hilt dependencies to build.gradle
- Convert RecommendationService to Hilt-provided singleton
- Create Hilt module for service binding
- Update all usage sites to inject service
- Add constructor injection for dependencies (OkHttpClient, etc.)
Benefits
- Easier unit testing with test doubles
- Cleaner dependency graph
- Scoped lifecycle management
- Consistent with rest of app architecture
Proposed Implementation
@Singleton
class RecommendationService @Inject constructor(
private val client: OkHttpClient,
private val authRepository: AuthRepository
) {
// Implementation
}
Acceptance Criteria
-
Hilt dependencies added -
Service converted to use @Inject -
All injection sites updated -
Unit tests use Hilt test framework -
No singleton getInstance() calls remain
Related Work
- Follow-up from !7 (merged) code review
- Aligns with mobile-section