Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda