Last active
June 2, 2020 04:39
-
-
Save bobbyirawan09/681db1f6ab31edfa6c301d3c8ae381d7 to your computer and use it in GitHub Desktop.
Example usage Koin in project
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
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