Created
January 31, 2018 08:22
-
-
Save LuigiPapino/424b4d85f94bb6e82e75476ccdac0cd9 to your computer and use it in GitHub Desktop.
Modular Architecture - Dagger2 - Application Component
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(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) | |
} | |
} |
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 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