bliessens / Kodein

Painless Kotlin Dependency Injection

Home Page:https://kosi-libs.org/kodein

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KODEIN

Kotlin Maven Central Github Actions MIT License Slack channel

KOtlin DEpendency INjection

KODEIN is a very simple and yet very useful dependency retrieval container. it is very easy to use and configure.

KODEIN works:

  • On the JVM.
  • On Android.
  • On Javascript (both in the browser and on Node.js).
  • On Native platforms (such as iOS).

KODEIN allows you to:

  • Lazily instantiate your dependencies when needed
  • Stop caring about dependency initialization order
  • Easily bind classes or interfaces to their instance or provider
  • Easily debug your dependency bindings and recursions

KODEIN provides extensions to be integrable into:

An example is always better than a thousand words:

val di = DI {
    bindProvider<Dice> { RandomDice(0, 5) }
    bindSingleton<DataSource> { SqliteDS.open("path/to/file") }
}

class Controller(private di: DI) {
    private val ds: DataSource by di.instance()
}

KODEIN is a good choice because:

  • It proposes a very simple and readable declarative DSL
  • It is not subject to type erasure (as Java is)
  • It integrates nicely with Android
  • It proposes a very kotlin-esque idiomatic API
  • It is fast and optimized (makes extensive use of inline)
  • It can be used in plain Java

Looking for KODEIN 7.0 migration guide?

Follow this us here.

Kotlin & JVM compatibility

Kodein Kotlin JDK Compose
7.17.1 1.8.0 min 1.8 Compatible
7.17.0 1.8.0 min 1.8 No
7.16.0 1.7.20 min 1.8 Compatible
7.15.1 1.7.20 min 1.8 Compatible (no JS)
7.15.0 1.7.20 min 1.8 No
7.14.0 1.7.10 min 1.8 Compatible
7.13.1 1.7.0 min 1.8 Compatible
7.13.0 1.7.0 min 1.8 No
7.12.0 1.6.21 min 1.8 Compatible
7.10.0 1.6.10 min 1.8 Compatible
7.7+ 1.5+ min 1.8 Compatible
7.6+ 1.5+ min 1.8 -
7.1+ 1.4+ min 1.8 -
7.0+ 1.3.72 min 1.8 -
6.5.5 1.3.72 min 1.8 -
6.5.4 1.3.71 min 1.8 -
6.5.3 1.3.70 min 1.8 -
6.5.0 1.3.61 min 1.8 -
6.4.1 1.3.50 min 1.8 -
6.3+ 1.3.40 min 1.8 -
6.2+ 1.3.30 1.6 -
6.1+ 1.3.20 1.6 -
6.0+ 1.3.0 1.6 -
5.0+ 1.2.30 1.6 -
4.1+ 1.1.3 1.6 -
4.0.0-beta2 1.1.0 1.6 -

Demo Projects

You can find samples for MPP project here https://github.com/kosi-libs/Kodein-Samples

Read more

KODEIN 7+ is the current major version, but documentation is available for previous versions.

Kodein documentation

Support

Support is held in the Kodein Slack channel (you can get an invitation to the Kotlin Slack here).

Testimonies

 

At Collokia we use Kodein in all of our backend service infrastructure and all modules in those services are loosely coupled through injection with Kodein. It allows us to have nice module independence, and to opt-out of injection during testing or build separate modules in support of testing.
It is a key component and building block in our architecture.
-- Jayson Minard

 

 

At Moovel Group GmbH, we have successfully used the wonderful Kodein library into in this Android app. As we improved it, we found Kodein to be much more useful than Dagger2 as it simplified our code throughout.
Kodein is in my view, much easier to understand, doesn't have that nasty ceremony, and has really nice debug messages.
We are also working now on other projects where we are using Kodein as well.
-- Sorin Albu-Irimies

 

 

Kodein has been instrumental in moving our entire production application to Kotlin at InSite Applications. It uses standard Kotlin idioms and features for ultimate clarity and simplicity. It was clear to us from the beginning that Kodein would be our DI solution. Our devs love it so much that they've transitioned to using it in their personal apps, both Java and Kotlin!
-- Eliezer Graber

 

 

At Compsoft Creative, Kodein is central our new Kotlin based app architecture, giving us a solid underpinning to all apps we develop and allowing a simple yet powerful way to de-couple our services with a library that is lightweight and perfect for mobile apps.
-- Daniel Payne

 

 

Kodein is used in the android app of the OhelShem school.
-- Yoav Sternberg 

 

Kodein was created at Dental Monitoring with the opinion that Dagger2 is way too verbose and complex. It is now used in almost all our projects: the server, the internal production software & the Android application.
Kodein is very easy to use and set up: it allows our team to easily share code and patterns, as well as quickly bootstrapping new ideas.
-- Salomon Brys

 

 

If you are using KODEIN, please let us know!

About

Painless Kotlin Dependency Injection

https://kosi-libs.org/kodein

License:MIT License


Languages

Language:Kotlin 97.6%Language:Java 2.4%