Scopes & Component Lifetimes
Control how long dependencies live.
What a Scope Controls
A scope decides how long Hilt keeps a single instance alive and where it gets shared. It is about lifetime, not just creation.
Unscoped by Default
Without a scope annotation, Hilt builds a new instance every time it is requested. That is fine for cheap, stateless objects.
@Provides
fun provideMapper(): Mapper = Mapper() // fresh each timeAll lessons in this course
- Why DI: Testable, Decoupled Code
- Modules, @Provides & @Binds
- hiltViewModel & @HiltViewModel
- Scopes & Component Lifetimes