Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Testing with Manual Dependency Injection according to Google

There is an article from Google about Manual Dependency Injection. In it, they use an Application class that holds an AppContainer, which itself holds dependencies that other classes might need:

class AppContainer {
    private val retrofit = Retrofit.Builder()...
    val userRepository = UserRepository(localDataSource, remoteDataSource)
}

An Activity might then do the following to get a dependency, eg. a repository:

val appContainer = (application as MyApplication).appContainer
val loginViewModel = LoginViewModel(appContainer.userRepository)

They state the following:

Dependency injection ... enables you to swap out implementations for testing.

Can this be done with that approach (or any of the others presented on the page mentioned above)?

I tried to come up with a canonical way and didn't find one that wouldn't involve reflection or mocking or anything of the sorts.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!