当前位置: 首页 > 软件库 > 手机/移动开发 > >

Kodein-DI

Painless Kotlin Dependency Injection
授权协议 MIT License
开发语言 Kotlin
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 胡鸿远
操作系统 Android
开源组织
适用人群 未知
 软件概览

KODEIN-DI

Github Actions

KOtlin DEpendency INjection

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

Kodein-DI works:

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

Kodein-DI 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-DI 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-DI 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-DI 7.0 migration guide?

Folow this us here.

Kotlin & JVM compatibility

Kodein-DI Kotlin JDK
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/Kodein-Framework/Kodein-Samples

Read more

Kodein-DI 7+ is the current major version, but documentation is available for previous versions.

Kodein-DI documentation

Support

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

Future

The following frameworks will receive special love from Kodein:

  • Android
  • Cocoa-Touch (iOS), // TODO
  • Ktor
  • TornadoFX

 

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-DI, please let us know!

  • Kodein是什么? 在网上关于它的资料并不是很多,这也证明它现在并不是很完善,之所以要写一系列关于Kodein的文章是为保证自己要一直学习新鲜事物。 这篇文章主要介绍Kodein在Android中如何使用 首先我们在app->build.gradle引入 implementation 'org.kodein.di:kodein-di-generic-jvm:6.5.0' implementati

  • Kodein是什么? 在网上关于它的资料并不是很多,这也证明它现在并不是很完善,之所以要写一系列关于Kodein的文章是为保证自己要一直学习新鲜事物。 下面我们着重介绍一下它的作用是什么?相信大家Dagger2这个框架已经用得很熟了,这里不在花篇幅去介绍Dagger2的好处,Kodein就是Dagger2的替代方案,它更加Kotlin。 我们去官网地址下载相关依赖 implementation '

  • 项目工程中之前用的4.1.0版本的Kodein.最近将Kodein升级到6.0.0.主要是工程现在没有适配AndroidX,Kodein6.0以上只找到AndroidX版本的,官网也没有什么历史版本索引,GitHub上文档也使用页面是白的,因此这次先升级到6.0.0。Kodein4.+到6.0的变化比较大,6.0以后变化就不是很大了这里这里记录以下6.0的新的语法调用。 配置依赖 配置依赖 imp

  • gradle下载中,闲的慌记录下Kodeinn Kodein有在类型擦拭问题上,有两种Flavor可选。 一种是常规不做处理, 一种是能够在运行时保留类型参数的。 注:类型擦拭简单解释,泛型作为类型参数,在编译成字节码之后其类型是不保留的,它的作用仅限于在编译前提供检查。 如: List<Sring> strsList=new ArrayList<>() strList.add("love wor

  • 用 Java 进行 Android 开发的话,依赖注入这一块一般使用 Dagger ,转用 Kotlin 之后有更多的选择,Kodein 是个不错的库, 4.0 5.0 都使用过了,相对于 Dagger 有很多好处。 用 Kotlin 编写利用了更优秀的语言特性 比如类型推断,Dagger 在编写 Component 的时候需要知道注入类的类型 无需像 Dagger 一样编写大量模板代码 不会像

  • 1、IoC(Inversion of Control)控制反转和 DI(Dependency Injection)依赖注入    首先想说说IoC(Inversion of Control,控制倒转)。这是spring的核心,贯穿始终。所谓IoC,对于spring框架来说,就是由spring来负责控制对象的生命周期和对象间的关系。这是什么意思呢,举个简单的例子,我们是如何找女朋友的?常见的情况是,

  • DI的三种依赖注入方式和底层实现? 1. 有参构造器注入 这种方式的前提是,在bean所对应的类中显式定义有参构造函数,涉及到的属性才能够使用<constructor-arg/>标签进行赋值。具体参照链接Spring IOC(控制反转)_鲸鱼-D的博客-CSDN博客中IOC创建对象方式中的方式2。 2.Set方式注入  前提: 类中有无参构造函数(默认or显式定义)以及setter方法。 3. 扩

  • 依赖注入 Notion – The all-in-one workspace for your notes, tasks, wikis, and databases. 控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。 依赖(dependency):指定了被依赖对象的类型,注入器会根据此类型创建对应的对象 注入(

  • IOC是一种编程思想。DI 是IOC的一种实现方式。除了DI方式,还可以用Service Locator去实现IOC。 什么是控制反转:当一个类需要使用一个组件或服务时,不在这个类里去实例化组件或服务。而是利用框架去创建。有类需要使用某一个组件时,框架依据配置将组件实例注入到这个类里。除了组件的创建,框架还负责组件的销毁。这样,组件生命周期的控制权交给了框架。 为什么要实现控制反转: 使用类中不再

  • 属性的依赖注入,spring在通过IOC创建对象的时候,如果对象还有属性,就一并给赋值进去,DI是在IOC的基础上进行对象的属性注入。

  • DI和DL其实是Spring IoC的两种方式,比如A类实体依赖B类实体和C类实体,DI是被动接受注入,那么A类就会被动接受Ioc容器为自己注入B类实体和C类实体。DL是主动寻找,A类实体就会主动去查找它依赖的B类实体和C类实体。