Skip to content

Instantly share code, notes, and snippets.

@bobbyirawan09
Last active June 2, 2020 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbyirawan09/681db1f6ab31edfa6c301d3c8ae381d7 to your computer and use it in GitHub Desktop.
Save bobbyirawan09/681db1f6ab31edfa6c301d3c8ae381d7 to your computer and use it in GitHub Desktop.
Example usage Koin in project
val exampleModule = module {
single {
B()
}
}
//startKoin{} in Application class, we will skipped it for now
class A (): KoinComponent() {
val b: B = get()
// val b: B by inject() -> lazy way
fun printSomething() {
b.printSomething() //will print `called from class A` when accessing this function
}
}
class B {
fun printSomething() {
println("called from class A")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment