Dagger Fundamentals & Manual DI Interview Questions
ARCHITECTURE › Dependency Injection
How does Dagger work at a high level, and how does Hilt relate to it?
What a strong answer covers: Dagger generates code at compile time to build the dependency graph from @Inject constructors, @Module providers and @Component interfaces, so injection is plain generated Java with no reflection, and missing bindings fail the build. Hilt is built on Dagger and provides standard components and entry points for Android classes so you don't write component boilerplate yourself.
What is manual dependency injection, and how would you do it without a framework?
What a strong answer covers: You create objects and pass dependencies through constructors yourself, usually in an AppContainer held by the Application that builds singletons like the database and repositories, plus factories for ViewModels. It's simple and explicit for small apps; it gets tedious as the graph grows, and lifetimes must be managed by hand.
What is the difference between a Component and a Subcomponent, or component dependencies, in Dagger?
What a strong answer covers: A Subcomponent is a child that inherits all parent bindings and has a shorter scope, declared from the parent. Component dependencies let one component use another's explicitly exposed bindings, more decoupled but with more boilerplate. Hilt uses a fixed hierarchy of subcomponents, which is why most apps no longer design this themselves.
What are Lazy<T> and Provider<T> in Dagger, and when would you use them?
What a strong answer covers: Provider<T> gives a new instance (or the scoped one) each time you call get(), useful for creating several objects or breaking certain cycles. Lazy<T> creates the instance on the first get() and caches it, deferring expensive construction until needed, which can help startup. Both help avoid initialising everything when a class is created.
How would you migrate a large app from Dagger to Hilt incrementally?
What a strong answer covers: Add Hilt alongside Dagger, annotate the Application with @HiltAndroidApp, and make the existing component a Hilt-aware entry point or install old modules into Hilt components with @InstallIn (or use @DisableInstallInCheck temporarily). Move screen by screen to @AndroidEntryPoint, mapping custom scopes to Hilt's. Watch for build time, conflicting scope semantics, and tests that build their own components. Migrating test setup to HiltAndroidTest is often the biggest task.