Not able to understand dagger dependency injection concepts - Dagger 2 on android : <p>I am trying to understand dagger2 and implement in my app. I have read a lot about its benefits. Unless and until I understand it completely, I cannot get the benefits of it in my app.</p>

<p>I have understood @Module and @Inject. The one that confuses me is @Component. I have few questions related to that. </p>

<ol>
<li><p>Module provides object instances and Inject uses it. Why do we need component in between? Is it really necessary to bridge the gap? Can we have empty Interface components without any methods?</p></li>
<li><p>Is constructor really necessary for module class? If there is no constructor in module class, Can we initialize module class using empty constructor?</p></li>
<li><p>Why can't we directly instantiate module class and build dependency graph instead of creating component and then initializing it?</p></li>
<li><p>I have seen only two kinds of methods in component interface so far</p>

<p>a. void inject(Activity/Service/Fragment); - Why do we need to provide an instance of activity or service or fragment to this method? why can't we have something like this - </p>

<p>void inject(); - Will the Component still generate dependency graph?</p>

<p>Can we inject from some other class other than activity or service or fragment something like this - </p>

<p>void inject(DataManager dataManager);</p>

<p>What If DataManager was a singleton instance?</p>

<p>b. Retrofit getRetrofit(); What is the difference between this method and above method? Why does not this take any input parameters?</p></li>
<li><p>I read that @Singleton is just a scope in dagger. How can we actually create a singleton object that lives for lifetime of the application?</p></li>
<li><p>Let's suppose there is a DataManager instance that I want to build using dagger. It is having only one dependency.  I wrote a module class and a component interface for that. If I want to use this in let's say MainActivity, i use it as </p>

<p>@Inject DataManager dataManager;</p>

<p>...</p>

<p>@Override</p>

<p>protected void onCreate(Bundle savedInstanceState) {</p>

<p>DataManagerComponent.Builder().DataManagerModule(new DataManagerModule()).build();</p>

<p>}</p>

<p>I want to use this datamanager in many other activities and I don't want it to be 
singleton. I want to keep it to the current activity scope where I use it. So I 
will use </p>

<p>@Inject DataManager dataManager; </p>

<p>to get that instance. Should I 
write </p>

<pre><code>DataManagerComponent.Builder...........
</code></pre>

<p>in each and every activity oncreate() where I use @Inject DataManager dataManager? If I have to write that, 
Will it not create more boilerplate code than simply using </p>

<p>DataManager dataManager = new DataManager();  </p></li>
<li><p>Let's suppose there are 4 objects and they are dependent on each other like D dependent on C, C dependent on B etc.</p>

<p>D -> C -> B -> A</p>

<p>Let's suppose I have written module class and provides method for all 4. If 
I try to inject D in any ActivityA like</p>

<p>@Inject D d;</p>

<p>Will C, B, A instantiated automatically?</p>

<p>Let's suppose in ActivityB I just need to inject B. If I inject B 
like </p>

<p>@Inject B b;</p>

<p>Will dagger create B and A again? Or will it use the ones which are already 
created ?</p></li>
</ol>

<p>I appreciate if someone takes time to answer all my questions. I don't expect detailed answer. It is fine if it clarifies the concept. Looking forward for the response. Thanks in advance. </p>
