Skip to content

Instantly share code, notes, and snippets.

View sampengilly's full-sized avatar

Sam Pengilly sampengilly

  • Brisbane, Australia
View GitHub Profile
@sampengilly
sampengilly / .ideavimrc
Last active April 29, 2026 22:20
.ideavimrc
" .ideavimrc is a configuration file for IdeaVim plugin. It uses
" the same commands as the original .vimrc configuration.
" You can find a list of commands here: https://jb.gg/h38q75
" Find more examples here: https://jb.gg/share-ideavimrc
let mapleader="\<Space>"
set nocompatible
""" Plugins
set surround
class MyActivity : Activity() {
private val myDependency by inject { myDependency() }
// ...
}
@Component(modules = [MyApplicationModule::class])
@Singleton
interface MyAppComponent {
// These functions will be auto-generated by Dagger to provide that specific dependency
fun myDependency(): MyDependency
// Inject methods such as this are the commonly documented method for injecting into JSR-330 annotated fields
fun inject(application: MyApplication)
@sampengilly
sampengilly / DaggerExt.kt
Last active July 26, 2018 01:25
Android example of Dagger extensions allowing injection to `private val` properties in Kotlin
inline fun <reified T> Fragment.inject(
noinline initializer: MyAppComponent.() -> T) = lazy {
context?.let {
(it.applicationContext as MyApplication).component.initializer()
} ?: throw IllegalStateException("Context must be set before accessing this property")
}
inline fun <reified T> Context.inject(
noinline initializer: MyAppComponent.() -> T
) = lazy(LazyThreadSafetyMode.NONE) {