Skip to content

koin: What is koin

Devrath edited this page Mar 8, 2024 · 5 revisions

1_phwqsPxATyTUbgkvJONgQA

Features of koin

  • It involves runtime code generation.
  • It uses a service locator design pattern.
  • It is built for kotlin.
  • It is written in kotlin fully.

How koin operates under the hood

Modules

  • Dependencies are defined in modules by grouping related instances.
  • Modules are created using the module function.

Dependencies

  • The dependencies are created in 3 ways - This refers to the desired lifecycle behavior.
    • Single
    • Factory
    • Scoped
  • Single ----> This creates a single instance of the desired dependency that is reused through the application lifecycle.
  • Factory ---> This creates a new instance of the object every time we request it.
  • Scoped ----> This creates a specific instance under a specific scope, It can be per activity, fragment, etc.

Injection

  • Dependencies are injected into the class using by inject() delegate that allows us to access the dependencies without instantiating them.

KoinContainer

  • Koin container holds all the modules in a container and provides the required dependencies as needed.
Clone this wiki locally