Dependency Injection

5 concepts · 10 practice questions

Why dependency injection

A class receives its dependencies instead of creating them. That makes it testable with fakes, keeps construction in one place, and lets lifetimes be managed centrally. Constructor injection is the default; a framework only automates the wiring.

class CheckoutViewModel(
    private val repo: CartRepository,   // given, not created
) : ViewModel()

Also covered

Hilt components
Scopes
@Binds vs @Provides
Qualifiers

Sign in to read the rest and take the 10-question test.

Sign in to continue