Last active
October 24, 2017 11:47
-
-
Save pbochenski/55ca6a881530f2e6131cd38aa19caa80 to your computer and use it in GitHub Desktop.
learning_dagger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
interface AppComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
DaggerAppComponent.builder().build() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class DaggerAppComponent implements AppComponent { | |
private DaggerAppComponent(Builder builder) {} | |
public static Builder builder() { | |
return new Builder(); | |
} | |
public static AppComponent create() { | |
return new Builder().build(); | |
} | |
public static final class Builder { | |
private Builder() {} | |
public AppComponent build() { | |
return new DaggerAppComponent(this); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = arrayOf(RestDModule::class)) | |
interface AppComponent { | |
fun inject(fragment: MainActivityAH) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = arrayOf(RestDModule::class)) | |
interface AppComponent { | |
fun inject(fragment: MainActivityAH) | |
fun inject(fragment: LoginActivityAH) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = arrayOf(RestDModule::class)) | |
interface AppComponent { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component = DaggerAppComponent.builder() | |
.restDModule(RestDModule("https://ig1oxjwy74.execute-api.us-east-1.amazonaws.com/dev/")) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivityAH : ActionHolder<MainActivityCommands, MainActivityState>() { | |
@Inject lateinit var repo: Repo | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
(activity.application as App).component.inject(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class RestDModule(private val baseUrl: String){ | |
@Provides | |
@Singleton | |
fun provideRepo() :Repo { | |
val client = OkHttpClient.Builder() | |
.addInterceptor(HttpLoggingInterceptor() | |
.apply { level = HttpLoggingInterceptor.Level.BODY }) | |
.build() | |
val api = Retrofit.Builder() | |
.baseUrl(baseUrl) | |
.client(client) | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync()) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build() | |
.create(LoginDojoApi::class.java) | |
return Repo(api) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment