Giter VIP home page Giter VIP logo

kodein's Introduction

KODEIN

Kotlin 1.0.7 Maven Central Travis MIT License GitHub issues Slack channel Donate

KOtlin DEpendency INjection

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

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 does not allow you to:

  • Automatically instantiate your dependencies via injected constructor and reflexivity. For that, you need Guice.
  • Have dependency injection validated at compile time. For that, you need Dagger.

Kodein is a good choice because:

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

Example

An example is always better than a thousand words:

val kodein = Kodein {
    bind<Dice>() with provider { RandomDice(0, 5) }
    bind<DataSource>() with singleton { SqliteDS.open("path/to/file") }
}

class Controller(private kodein: Kodein) {
    private val ds: DataSource = kodein.instance()
}

Read more

Kodein version 3 is the current major version available:

If you are currently using a javax.inject compatible dependency injection library and whish to migrate to Kodein, there is a guide for that.

Who uses Kodein?

Well, I'd like to know!

If you are using Kodein, please let me know by mail.

A public list will be displayed here soon :)

kodein's People

Contributors

salomonbrys avatar eygraber avatar udalov avatar davidschreiber avatar coreydowning avatar dsvoronin avatar jdigger avatar jkschneider avatar k-kagurazaka avatar roosmaa avatar dnlbauer avatar renanlukas avatar avh4 avatar

Stargazers

 avatar

Watchers

Marko Salmela avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.