Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Why do we require dependency Injection in android when we can simply pass the references of other classes through constructor?

Posted on November 11, 2022 By

Solution 1 :

There is no problem in simply passing references of classes in the constructor of the dependent class.

Motive behind using dependency injection is to simplify the complexity of code as dependency injection provides the re-usability of classes and decoupling of dependencies making code easy to refactor and test.

More Detail

Problem :

I am learning usage of DI in android and more often I have came across how we are required to use dependency Injection. Before that while developing apps I used to simply pass references of classes in the constructor of the dependent class. Why can’t we keep doing that rather than using constructor Injection? Thank you.

Comments

Comment posted by developer.android.com/training/…

Dependency injection provides your app : Reusability of classes and decoupling of dependencies check out more on

Comment posted by Steven

Can you show some examples that demonstrate what the difference is between “simply pass references of classes in the constructor of the dependent class” and what you consider to be “constructor injection”?

Comment posted by charmcaster

While giving interview at Uber the interviewer asked me this question why I am using @Inject constructor , for example in MVVM while passing reference of Repository class into viewmodel constructor. He asked me why I am using dependency Injection if I can simply pass the reference.

READ  [FIXED] android - How to set permanatly flutter sdk path in anroid studio?
Powered by Inline Related Posts
Android Tags:android, dagger-hilt, dependency-injection

Post navigation

Previous Post: [FIXED] android developer api – there is a ‘Late Initialization Error’ during flutter development
Next Post: [FIXED] android – How to set SSL pinning using retrofit for Firebase Realtime Database Url?

Related Posts

[FIXED] java – Best approach to map data of variable length to a fixed structure? Android
[FIXED] How to detect android contact updated and sync to firestore Android
[FIXED] android – How can I solve this problem while creating recyclerview? Android
[FIXED] android – How redirect Timber logs to Junit logcat Android
[FIXED] bluetooth – BLE data transfer speed Android
[FIXED] android studio – why my TabLayout inside Fragment only work in first time? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme