Skip to content

Instantly share code, notes, and snippets.

@LuigiPapino
Created January 31, 2018 08:22
Show Gist options
  • Save LuigiPapino/424b4d85f94bb6e82e75476ccdac0cd9 to your computer and use it in GitHub Desktop.
Save LuigiPapino/424b4d85f94bb6e82e75476ccdac0cd9 to your computer and use it in GitHub Desktop.
Modular Architecture - Dagger2 - Application Component
@Singleton
@Component(modules = arrayOf(NetworkModule::class, RepositoryModule::class, SubcomponentModule::class))
interface ApplicationComponent : AndroidInjector<MyApplication> {
val userRepository: UserRepository
val apiService: ApiService
fun browserBuilder(): BrowserSubComponent.Builder
}
@Module
object NetworkModule {
@Provides
@Singleton
@JvmStatic
fun provideApiService(okHttp: OkHttp): ApiService {
return ApiSerive(okHttp)
}
}
class MyApplication : BaseApplication() {
lateinit var appComponent: ApplicationComponent
override fun onCreate() {
appComponent = DaggerApplicationComponent
.builder()
.create(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment