Skip to content

Instantly share code, notes, and snippets.

@pokk
Last active December 3, 2017 02:42
Show Gist options
  • Save pokk/d68f06f62b2b4ef0c90733c2513fb1ea to your computer and use it in GitHub Desktop.
Save pokk/d68f06f62b2b4ef0c90733c2513fb1ea to your computer and use it in GitHub Desktop.
class App: Application() {
companion object {
lateinit private var context: Context
@JvmStatic fun appComponent(): AppComponent = (context as App).appComponent
// Provide the global application context.
@JvmStatic fun getAppContext(): Context = context
}
// Before dagger 2.11
private val appComponent: AppComponent by lazy { AppComponent.Initializer.init(App@ this) }
override fun onCreate() {
super.onCreate()
context = this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment