October 2019
Intermediate to advanced
434 pages
11h 54m
English
Another domain where Kotlin DSLs have cropped up is that of dependency injection, or dependency retrieval. Koin and Kodein are libraries that allow you to get your application dependencies through a type of object graph.
Using Kodein, we can develop our object graph using a variety of functions, as demonstrated in the following example:
val kodein = Kodein { bind<GreetingProvider>() with provider { FriendlyGreetingProvider() } bind<Repository>() with singleton { NetworkRepository() } } class ViewModel(private kodein: Kodein) { private val repo: Repository by kodein.instance() }
Now that we understand what DSLs are, in the next section, we'll start to explore how DSLs are built using Kotlin.
Read now
Unlock full access