Dagger 2 Android using Retrofit :

Raviraj Desai
1 min readMar 14, 2018

What is Dependency Injection? Dependency Injection is a design pattern, or you can say a concept of Object Oriented Programming, where we don’t create an object of another class inside a class using the new keyword (for Java). Instead, we supply the needed object from outside.

SourceCode

https://github.com/rajextreme9476/MyApplication

Project Structure

Set it up in build.gradle file:

//these two lines for dagger
compile 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'

Output

--

--

Raviraj Desai

Assistant Vice President at HDFC Bank (Android — Kotlin lover. Tech stack: MVVM, Dagger2, Coroutines, RxJava2 ,Flutter Enthusiast ,Ejabber