Skip to content
RED SAGSkills
mediumMobile App Developer interview question

What is dependency injection and how have you used it in a mobile app?

What the interviewer wants to hear

  • Objects receive dependencies instead of creating them
  • Makes testing easy by swapping fakes
  • Tools: Hilt/Dagger, Koin, Swift initializer injection, get_it or Riverpod
  • Scopes like singleton, per screen
  • Avoid service locator overuse and hidden globals

Model answer

Dependency injection means a class gets the objects it needs from outside, usually through its constructor, instead of creating them itself. For example, a ProfileViewModel receives a UserRepository rather than building its own Retrofit client. This makes the code loosely coupled and easy to test, because in a unit test I can pass a fake repository. On Android I have used Hilt, which generates the wiring at compile time and handles scopes such as singleton for the database and ViewModel scope for screen objects. In Swift I usually do plain initializer injection with protocols, and in Flutter I have used Riverpod. I try to avoid hidden global singletons, because they make tests depend on each other and hide what a class really needs.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Mobile App Developer questions