Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda