0

I am new to Dagger, though I understand that injection can be achieved in two ways(as far as I can conclude) that by injecting constructor using @Inject and by using @Provide in the Module.

Still my conclusion doesn't have a valid point wrt to realtime scenarios and example. Any suggestions will be helpful. Thank You

  • 1
    Does this answer your question? [Android Dagger 2: Inject versus Provides](https://stackoverflow.com/questions/39207845/android-dagger-2-inject-versus-provides) – denvercoder9 May 24 '20 at 19:24
  • Also, please go through this documentation on [d.android.com](https://developer.android.com/training/dependency-injection/dagger-android). It's a good summary of the most common or important apis. – denvercoder9 May 24 '20 at 19:27

1 Answers1

0

Yes, there are two types of injection, Constructor and Field injection. Annotating fields for injection tells dagger to inject the proper object into them. Annotating constructor for injection tells dagger to inject required objects and also allows dagger to create an instance of the class if it was needed somewhere else.

On the other hand, there is @Provide which is something different. with 'Provide' you provide dagger with required objects and dagger will inject them wherever they are needed. You define how to instantiate an object for injection.

Ali Gadimi
  • 51
  • 8