Painless Kotlin Dependency Injection

Overview

KODEIN-DI

Kotlin Maven Central Github Actions MIT License Slack channel

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.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!

Comments
  • Kodein android components

    Kodein android components

    @SalomonBrys The last commit is the big one that has some questions

    1. I left out KodeinAppCompatActivity because kodein-android only imports support-v4. I didn't want to start changing the whole build process (because the appcompat support library is an AAR as opposed to a JAR). Users can still make their own KodeinAppCompatActivity if the absolutely need it (we could put the proper code for it in the docs).
    2. I went with KodeinInjector instead of LazyKodein because it seemed safer when working with Android. Any thoughts on that?
    3. What do you think of the overall concept?

    I haven't written any docs yet; would like to hear what you think first.

    Here's a sample of how it could be used:

    class MyApplication : Application(), KodeinAware {
      override val kodein by Kodein.lazy {
        import(autoAndroidModule([email protected]))
    
        bind<String>() with instance("Hello, Kodein Android!")
      }
    }
    
    class MyActivity : KodeinFragmentActivity() {
      private val test: Test by injector.with(this as Activity).instance()
      private val testOther: Test by injector.with(this as Activity).instance()
      private val alarmManager: AlarmManager by injector.instance()
    
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        Log.e("TEST", "$test $testOther")
      }
    
      override fun provideBindings(): Kodein.Module? {
        return Kodein.Module {
          bind<Test>() with activitySingleton { Test(instance(), instance(), instance()) }
        }
      }
    }
    
    class Test(injector: KodeinInjected, message: String, activity: Activity) {
      private val prefs: SharedPreferences by injector.instance()
    
      init {
        Log.e("TEST", "$message - $prefs - $activity")
      }
    }
    
    opened by eygraber 24
  • Kodein 7 Doesn't Protect Bound interface from R8 Dead Code Elimination

    Kodein 7 Doesn't Protect Bound interface from R8 Dead Code Elimination

    Our Android app is using R8 in full mode for release builds, and we've run into issues with Kodein 7, where it marks some of our interfaces as dead code, which causes a crash at runtime. There is no issue with Kodein 6.

    Neither AgeValidator nor AgeValidatorImpl are referenced anywhere other than in the kodein binding.

    interface AgeValidator {
      fun validate(age: LocalDate): Boolean
    }
    
    internal class AgeValidatorImpl : AgeValidator {
      override fun validate(age: LocalDate) = true // not the actual implementation; condensed for clarity
    }
    
    val validatorModule = DI.Module("Validators") {
      bind<AgeValidator>() with provider {
        AgeValidatorImpl()
      }
    }
    
    class MyApp : Application(), DIAware {
      override val di = DI.lazy {
        import(validatorModule)
      }
    }
    

    The crash at runtime is:

    Binding bind<Any>() with ? { ? } must not override an existing binding.
    

    Digging into the bytecode on Kodein 6 yields the following for AgeValidator and AgeValidatorImpl:

    // AgeValidator
    .class public interface abstract LiK0;
    .super Ljava/lang/Object;
    .source "AgeValidator.kt"
    
    // AgeValidatorImpl; note that validate is not present because R8 eliminated it
    .class public final LjK0;
    .super Ljava/lang/Object;
    .source "AgeValidator.kt"
    
    # interfaces
    .implements LiK0;
    
    
    # direct methods
    .method public constructor <init>()V
        .registers 1
    
        .line 18
        invoke-direct {p0}, Ljava/lang/Object;-><init>()V
    
        return-void
    .end method
    

    For Kodein 7, AgeValidator has been completely eliminated and reduced into Any, so that now AgeValidatorImpl simply extends Any:

    // AgeValidatorImpl
    .class public final LDE1;
    .super Ljava/lang/Object;
    .source "AgeValidator.kt"
    
    
    # direct methods
    .method public constructor <init>()V
        .registers 1
    
        .line 18
        invoke-direct {p0}, Ljava/lang/Object;-><init>()V
    
        return-void
    .end method
    

    The crash makes sense, because AgeValidator gets replaced with Any which transforms validatorModule into:

    val validatorModule = DI.Module("Validators") {
      bind<Any>() with provider {
        AgeValidatorImpl()
      }
    }
    

    which crashes the second time this happens because we try binding Any twice, and don't allow overriding.

    I'm not sure what changed in Kodein 7 that would cause R8 to not recognize usage of a class as a type parameter for bind, but something did.

    opened by eygraber 20
  • InvalidMutabilityException caused by presenter injection

    InvalidMutabilityException caused by presenter injection

    Kodein 7.1.0 Kotlin 1.4.10 Ktor 1.4.1 Corutines 1.3.9-native-mt-2

    Application is crashing on iOS, but on Android is working fine.

            super.init(
                contentView: NewDeviceContentView(),
                presenter: CommonLibraryInitializer.init().provideBeaconRegistrationPresenter(),
                coordinator: coordinator,
                shouldReattachWhenAppear: false
            )
    

    fun provideBeaconRegistrationPresenter() = PresentationKodeinProvider.kodein.direct.instance<BeaconRegistrationPresenter>()

    Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen [email protected]
        at 0   CompanyCommon                      0x0000000105c359fd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
        at 1   CompanyCommon                      0x0000000105c2e39b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
        at 2   CompanyCommon                      0x0000000105c2e5eb kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
        at 3   CompanyCommon                      0x0000000105c6578b kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
        at 4   CompanyCommon                      0x0000000105c67042 ThrowInvalidMutabilityException + 690 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:92:11)
        at 5   CompanyCommon                      0x0000000105d64ddc MutationCheck + 108
        at 6   CompanyCommon                      0x0000000105c483e0 kfun:kotlin.collections.HashMap.<set-length>#internal + 80 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:16:17)
        at 7   CompanyCommon                      0x0000000105c4cf7f kfun:kotlin.collections.HashMap#addKey(1:0){}kotlin.Int + 1231 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:292:36)
        at 8   CompanyCommon                      0x0000000105c49483 kfun:kotlin.collections.HashMap#put(1:0;1:1){}1:1? + 355 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:68:21)
        at 9   CompanyCommon                      0x0000000105ec1af7 kfun:org.kodein.di.bindings.StandardScopeRegistry#getOrCreate(kotlin.Any;kotlin.Boolean;kotlin.Function0<org.kodein.di.bindings.Reference.Local<kotlin.Any,org.kodein.di.bindings.Reference<kotlin.Any>>>){}kotlin.Any + 1447 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/scopes.kt:65:27)
        at 10  CompanyCommon                      0x0000000105ec77f2 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3#internal + 546 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:22)
        at 11  CompanyCommon                      0x0000000105ec7ca4 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$FUNCTION_REFERENCE$83.invoke#internal + 212 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:125:16)
        at 12  CompanyCommon                      0x0000000105ed9ab1 kfun:org.kodein.di.internal.DIContainerImpl.factory$lambda-2#internal + 241 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:22)
        at 13  CompanyCommon                      0x0000000105eda5fc kfun:org.kodein.di.internal.DIContainerImpl.$factory$lambda-2$FUNCTION_REFERENCE$98.invoke#internal + 204 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:20)
        at 14  CompanyCommon                      0x0000000105eb83d2 kfun:org.kodein.di.DIContainer.provider$<anonymous>_1#internal + 194 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/DIContainer.kt:23:1)
        at 15  CompanyCommon                      0x0000000105eb87dd kfun:org.kodein.di.DIContainer.$provider$<anonymous>_1$FUNCTION_REFERENCE$25.invoke#internal + 157 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/DIContainer.kt:22:37)
        at 16  CompanyCommon                      0x0000000105eec458 kfun:org.kodein.di.internal.DirectDIBaseImpl#Instance(org.kodein.type.TypeToken<0:0>;kotlin.Any?){0§<kotlin.Any>}0:0 + 984 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DirectDIImpl.kt:30:153)
        at 17  CompanyCommon                      0x0000000105815063 kfun:com.Company.data.di.deviceConnectionModule$lambda-35$lambda-0#internal + 963 (/Users/mateuszkrawczuk/android-Company-client/Company-mobile-multiplatform/data/src/commonMain/kotlin/com/Company/data/di/deviceConnectionModule.kt:64:52)
        at 18  CompanyCommon                      0x000000010582ec83 kfun:com.Company.data.di.$deviceConnectionModule$lambda-35$lambda-0$FUNCTION_REFERENCE$358.invoke#internal + 179 (/Users/mateuszkrawczuk/android-Company-client/Company-mobile-multiplatform/data/src/commonMain/kotlin/com/Company/data/di/deviceConnectionModule.kt:64:52)
        at 19  CompanyCommon                      0x0000000105ec7332 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3$lambda-2$lambda-1#internal + 370 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:96)
        at 20  CompanyCommon                      0x0000000105ec7eb1 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$lambda-2$lambda-1$FUNCTION_REFERENCE$84.invoke#internal + 161 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:67)
        at 21  CompanyCommon                      0x0000000105ebfd37 kfun:org.kodein.di.bindings.Reference.Local.Companion#invoke(kotlin.Function0<0:0>;kotlin.Function1<0:0,0:1>){0§<kotlin.Any>;1§<org.kodein.di.bindings.Reference<0:0>>}org.kodein.di.bindings.Reference.Local<0:0,0:1> + 343 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/references.kt:16:127)
        at 22  CompanyCommon                      0x0000000105ec0c4a kfun:org.kodein.di.bindings.Strong.Companion#make(kotlin.Function0<0:0>){0§<kotlin.Any>}org.kodein.di.bindings.Reference.Local<0:0,org.kodein.di.bindings.Strong<0:0>> + 330 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/references.kt:31:97)
        at 23  CompanyCommon                      0x0000000105ec7547 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3$lambda-2#internal + 391 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:62)
        at 24  CompanyCommon                      0x0000000105ec80b1 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$lambda-2$FUNCTION_REFERENCE$85.invoke#internal + 161 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:51)
        at 25  CompanyCommon                      0x0000000105ec19ee kfun:org.kodein.di.bindings.StandardScopeRegistry#getOrCreate(kotlin.Any;kotlin.Boolean;kotlin.Function0<org.kodein.di.bindings.Reference.Local<kotlin.Any,org.kodein.di.bindings.Reference<kotlin.Any>>>){}kotlin.Any + 1182 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/scopes.kt:64:43)
        at 26  CompanyCommon                      0x0000000105ec77f2 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3#internal + 546 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:22)
        at 27  CompanyCommon                      0x0000000105ec7ca4 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$FUNCTION_REFERENCE$83.invoke#internal + 212 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:125:16)
        at 28  CompanyCommon                      0x0000000105ed9ab1 kfun:org.kodein.di.internal.DIContainerImpl.factory$lambda-2#internal + 241 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:22)
        at 29  CompanyCommon                      0x0000000105eda5fc kfun:org.kodein.di.internal.DIContainerImpl.$factory$lambda-2$FUNCTION_REFERENCE$98.invoke#internal + 204 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:20)
    CoreSimulator 732.17 - Device: iPhone 8 (777479B4-8C83-494D-92DA-6EA9D0CE3133) - Runtime: iOS 14.1 (18A8394) - DeviceType: iPhone 8
    
    opened by MateuszKrawczuk 17
  • 6.3.0 - 2 Bindings Found that Match False Positive

    6.3.0 - 2 Bindings Found that Match False Positive

    I updated to 6.3.0 from 6.2.0 and I got this crash:

    org.kodein.di.Kodein$NotFoundException: 2 bindings found that match bind<GlideListener<Drawable>>() with ?<MyActivity>().? { String -> ? }:
                module Media2 {
                    bind<GlideListener<Drawable>>() with factory { String -> GlideListener<*> }
                }
                module Util {
                    bind<DateFormat>() with factory { String -> SimpleDateFormat }
                }
    

    They are bound as:

    Bind<GlideListener<Drawable>>(generic()) with factory { name: String ->
        GlideListener<Drawable>(
            log = instance(arg = GlideListener.TAG),
            name = name
        )
      }
    
    bind<DateFormat>() with factory { pattern: String ->
        SimpleDateFormat(pattern, Locale.getDefault())
      }
    
    at org.kodein.di.internal.KodeinContainerImpl.factory(KodeinContainerImpl.kt:192)
            at org.kodein.di.KodeinContainer$DefaultImpls.factory$default(KodeinContainer.kt:33)
            at org.kodein.di.internal.DKodeinBaseImpl.Factory(DKodeinImpl.kt:18)
            at org.kodein.di.internal.BindingKodeinImpl.Factory(Unknown Source:12)
            at org.kodein.di.DKodeinBase$DefaultImpls.Factory$default(DKodein.kt:53)
            at com.myapp.di.modules.MediaKt$mediaModule$1$3.invoke(media.kt:58)
            at com.myapp.di.modules.MediaKt$mediaModule$1$3.invoke(Unknown Source:4)
            at org.kodein.di.bindings.Factory$getFactory$1.invoke(standardBindings.kt:20)
            at org.kodein.di.internal.DKodeinBaseImpl.Instance(DKodeinImpl.kt:32)
            at com.myapp.di.modules.AuthKt$authModule$1$5.invoke(auth.kt:119)
            at com.myapp.di.modules.AuthKt$authModule$1$5.invoke(Unknown Source:2)
            at org.kodein.di.bindings.Provider$getFactory$1.invoke(standardBindings.kt:88)
            at org.kodein.di.bindings.Provider$getFactory$1.invoke(standardBindings.kt:82)
            at org.kodein.di.KodeinContainer$provider$$inlined$toProvider$1.invoke(curry.kt:14)
            at org.kodein.di.internal.DKodeinBaseImpl.Instance(DKodeinImpl.kt:30)
            at com.myapp.di.modules.UtilsKt$utilModule$1$21.invoke(utils.kt:536)
            at com.myapp.di.modules.UtilsKt$utilModule$1$21.invoke(Unknown Source:2)
            at org.kodein.di.bindings.Singleton$getFactory$1$1$1.invoke(standardBindings.kt:130)
            at org.kodein.di.bindings.SingletonReference.make(references.kt:34)
            at org.kodein.di.bindings.Singleton$getFactory$1$1.invoke(standardBindings.kt:130)
            at org.kodein.di.bindings.Singleton$getFactory$1$1.invoke(standardBindings.kt:98)
            at org.kodein.di.bindings.StandardScopeRegistry.getOrCreate(scopes.kt:65)
            at org.kodein.di.bindings.Singleton$getFactory$1.invoke(standardBindings.kt:130)
            at org.kodein.di.bindings.Singleton$getFactory$1.invoke(standardBindings.kt:98)
            at org.kodein.di.KodeinContainer$provider$$inlined$toProvider$1.invoke(curry.kt:14)
            at org.kodein.di.KodeinAwareKt$Instance$1.invoke(KodeinAware.kt:176)
            at org.kodein.di.KodeinAwareKt$Instance$1.invoke(Unknown Source:4)
            at org.kodein.di.KodeinProperty$provideDelegate$1.invoke(properties.kt:42)
            at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
            at com.myapp.core.MyActivity.getPresenter(Unknown Source:7)
            at com.myapp.core.MyActivity.onCreate(MyActivity.kt:62)
            at android.app.Activity.performCreate(Activity.java:7144)
            at android.app.Activity.performCreate(Activity.java:7135)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
            	... 11 more
    
    type: bug 
    opened by eygraber 17
  • Gradle error: Cannot choose between the following variants of org.kodein.di:kodein-di-core:6.4.1

    Gradle error: Cannot choose between the following variants of org.kodein.di:kodein-di-core:6.4.1

    I get the following Gradle error at compile time when trying to build simple Hello World code, as a preparation to play with Kodein, using Intellij IDEA 2019.2.3 CE. How do I fix it?

    Main.kt

    fun main() {
        println("Hello, World!")
    }
    

    build.gradle

    dependencies {
        implementation 'org.kodein.di:kodein-di-generic-jvm:6.4.1'
    }
    

    Project SDK JDK 1.8.0_222

    Error

    Execution failed for task ':kaptKotlin'.
    > Could not resolve all files for configuration ':_classStructurekaptKotlin'.
       > Could not resolve org.kodein.di:kodein-di-core:6.4.1.
         Required by:
             project : > org.kodein.di:kodein-di-generic-jvm:6.4.1
          > Cannot choose between the following variants of org.kodein.di:kodein-di-core:6.4.1:
              - androidArm32-api
              - androidArm64-api
              - iosArm32-api
              - iosArm64-api
              - iosX64-api
              - js-api
              - js-runtime
              - jvm-api
              - jvm-runtime
              - linuxArm32Hfp-api
              - linuxMips32-api
              - linuxMipsel32-api
              - linuxX64-api
              - macosX64-api
              - metadata-api
              - mingwX64-api
              - wasm32-api
            All of them match the consumer attributes:
              - Variant 'androidArm32-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'android_arm32' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'androidArm64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'android_arm64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'iosArm32-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'ios_arm32' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'iosArm64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'ios_arm64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'iosX64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'ios_x64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'js-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'js' but wasn't required.
              - Variant 'js-runtime' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'js' but wasn't required.
              - Variant 'jvm-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.libraryelements 'jar' but wasn't required.
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'java-api' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
              - Variant 'jvm-runtime' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.libraryelements 'jar' but wasn't required.
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'java-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
              - Variant 'linuxArm32Hfp-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'linux_arm32_hfp' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'linuxMips32-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'linux_mips32' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'linuxMipsel32-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'linux_mipsel32' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'linuxX64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'linux_x64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'macosX64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'macos_x64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'metadata-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'common' but wasn't required.
              - Variant 'mingwX64-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'mingw_x64' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
              - Variant 'wasm32-api' capability org.kodein.di:kodein-di-core:6.4.1:
                  - Unmatched attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Found org.gradle.usage 'kotlin-api' but wasn't required.
                      - Found org.jetbrains.kotlin.native.target 'wasm32' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
    
    opened by tatsuyafujisaki 14
  • StandardScopeRegistry not returning Singleton instance for a given Scope

    StandardScopeRegistry not returning Singleton instance for a given Scope

    I am trying to inject the singleton dependencies of config manager in different modules for which I c created a Scope and Context containing StandardScopeRegistry. But it doesn't work. Following is the sample code:

    Approach 1

    class A.kt

    import org.kodein.di.bindings.Scope
    import org.kodein.di.bindings.ScopeRegistry
    import org.kodein.di.bindings.StandardScopeRegistry
    
    object SingletonScope : Scope<GlobalKodeinContext> {
    
        override fun getRegistry(context: GlobalKodeinContext): ScopeRegistry =
                context.standardScopeRegistry as? ScopeRegistry
                        ?: StandardScopeRegistry().also { context.standardScopeRegistry = it }
    
    }
    
    class GlobalKodeinContext {
    
        var standardScopeRegistry = StandardScopeRegistry()
    
    }
    
    

    Bindings.kt

    val deploymentConfigManagerBinding = Kodein.Module("deployment_config_manager", false) {
          bind<IConfigManager>() with scoped(SingletonScope).singleton { ConfigManager() }
    }
    
    

    class B.kt

    private val configManager: IConfigManager by kodein.on(context = GlobalKodeinContext()).instance<IConfigManager>()
    
    configManager.initializeConfigs(values)
    

    class C.kt

    private val configManager: IConfigManager by kodein.on(context = GlobalKodeinContext()).instance<IConfigManager>()
    
    configManager.getConfigs()
    

    Approach 2 I do not prefer static context objects, but tried anyway as nothing works

    GlobalKodeinContext.kt

    class GlobalKodeinContext {
        companion object {
            var appContext: Application? = null //Setting this in MainApplication with `this`
        }
    }
    

    Bindings.kt

    val deploymentConfigManagerBinding = Kodein.Module("deployment_config_manager", false) {
        bind<IConfigManager>() with scoped(WeakContextScope.of<Application>()).singleton { ConfigManager() }
    
        registerContextTranslator { context: Application -> context.applicationContext }
    }
    
    

    A.kt

    override val kodeinContext = kcontext(GlobalKodeinContext.appContext)
    
    private val configManager: IConfigManager by instance()
    
    configManager.initializeConfigs(values)
    

    B.kt

    override val kodeinContext = kcontext(GlobalKodeinContext.appContext)
    
    private val configManager: IConfigManager by instance()
    
    configManager.getConfigs()
    

    configManager.getConfigs() gives null pointer exception in both approaches as the configurations are not initialized for the singleton object injected in class C.

    I believe the context creation is incorrect. Please help. Thank you!

    opened by shasharm 13
  • Please guide : org.kodein.di.Kodein$NotFoundException: No binding found

    Please guide : org.kodein.di.Kodein$NotFoundException: No binding found

    Hi Team,

    I am not sure if this is an issue or I am doing something wrong. Please guide.

    Issue :

    org.kodein.di.Kodein$NotFoundException: No binding found for bind<WeatherForecastDatabase>() with ?<CurrentWeatherFragment>().? { ? }
        Registered in this Kodein container:
                bind<CurrentWeatherDao>() with singleton { CurrentWeatherDao }
                bind<CurrentWeatherViewModelFactory>() with provider { CurrentWeatherViewModelFactory }
                bind<Unit>() with singleton { Unit }
                bind<WeatherNetworkDataSource>() with singleton { WeatherNetworkDataSourceImpl }
                bind<WeatherForecastRepository>() with singleton { WeatherForecastRepositoryImpl }
                bind<ConnectivityInterceptor>() with singleton { ConnectivityInterceptorImpl }
                bind<WeatherApiService>() with singleton { WeatherApiService }
    

    I am using below grade dependencies,

    implementation "org.kodein.di:kodein-di-generic-jvm:6.1.0"
    implementation "org.kodein.di:kodein-di-framework-android-x:6.1.0"
    

    Here is my Application class below, which I have also added in AndroidManifest.xml,

    class WeatherForecastApplication : Application(), KodeinAware {
    
        override val kodein = Kodein.lazy {
            import(androidXModule([email protected]))
    
            bind() from singleton { WeatherForecastDatabase(instance()) }
    
            bind() from singleton { instance<WeatherForecastDatabase>().getCurrentWeatherDao() }
    
            bind<ConnectivityInterceptor>() with singleton { ConnectivityInterceptorImpl(instance()) }
    
            bind() from singleton { WeatherApiService(instance()) }
    
            bind<WeatherNetworkDataSource>() with singleton { WeatherNetworkDataSourceImpl(instance()) }
    
            bind<WeatherForecastRepository>() with singleton { WeatherForecastRepositoryImpl(instance(), instance()) }
    
            bind() from provider { CurrentWeatherViewModelFactory(instance()) }
        }
    
        override fun onCreate() {
            super.onCreate()
    
            // init threetenbp library.
            AndroidThreeTen.init(this)
        }
    
    }
    

    And this is how I am referencing instances in Fragment,

    class CurrentWeatherFragment : Fragment(), KodeinAware {
        override val kodein by kodein()
        private val factory: CurrentWeatherViewModelFactory by instance()
    
        private lateinit var viewModel: CurrentWeatherViewModel
    
        override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? {
            return inflater.inflate(R.layout.current_weather_fragment, container, false)
        }
    
        override fun onActivityCreated(savedInstanceState: Bundle?) {
            super.onActivityCreated(savedInstanceState)
            viewModel = ViewModelProviders.of(this, factory).get(CurrentWeatherViewModel::class.java)
        }
    }
    
    opened by GautamMandsorwale 13
  • Add support for testing injection.

    Add support for testing injection.

    Hi, I'm trying to write some espresso tests with Kotlin and using Kodein for DI. The technique I'm using is based on the replacement of production code using test doubles.

    When using Kodein from my instrumentation tests everything works like a charm. If I replace the application graph with a custom one before the test is executed and every dependency is provided before the test activity is launched everything works as expected. This is working because I can replace the application module using one created from my test. But I've found a problem when the module used is initialized from the activity and not from the application. Here you have an initialization example when running a test:

    The application starts: the app module is configured and initialized. The test starts: My test module, configured with some test doubles, is added. The activity is initialized: The activity modules are added to the graph.

    Expected result: The graph does not replace the already configured dependencies using a test double. Actual result: If I use the "override" param I lost my test module provision because the dependency has been replaced with the new one. If I remove the "override" param the app crashes.

    I'd like to propose a feature request where by configuration we could allow a silent injection that doesn't apply the override and does not throw any exception. If you are ok with this new feature I can send a pull request.

    I'd really like to resolve this issue even if you think there is a better approach. We can use this issue to talk about and after that send a PR :)

    I found a tricky solution that allows to me fix this problem but I adding coding in production related with the tests and this is not the best solution.

    if you like to view our approach for Java code you can read this blog post http://blog.karumi.com/world-class-testing-development-pipeline-for-android-part-4/

    Thanks for your time and this awesome library!

    opened by flipper83 13
  • Support for custome scopes

    Support for custome scopes

    Please add support for custome scopes. Now there is possibility to implement custome scope but ot would be nice to have some generic mechanism to use scopes just by define some scope identifier.

    opened by pawelByszewski 12
  • Update to kotlin 1.4.0

    Update to kotlin 1.4.0

    New version of kotlin (1.4.0) released.

    When I use it with kodein-di-jvm 7.0.0 I have these warnings appearing:

    [WARNING] Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
        ../.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.4.0/kotlin-stdlib-1.4.0.jar (version 1.4)
        ../.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.4.0/kotlin-stdlib-common-1.4.0.jar (version 1.4)
        ../.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.4.0/kotlin-reflect-1.4.0.jar (version 1.4)
        ../.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.3.72/kotlin-stdlib-jdk7-1.3.72.jar (version 1.3)
        ../.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.71/kotlin-stdlib-jdk8-1.3.71.jar (version 1.3)
    [WARNING] Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
    
    opened by NatsuOnFire 11
  • Is it possible to change Singleton (or any parameter) values after the initial Kodein instantiation?

    Is it possible to change Singleton (or any parameter) values after the initial Kodein instantiation?

    I’d really like to be able to change the value of my HTTP clients baseUrl value, because it can be set dynamically while using the application. I’m having trouble finding a way to change parameter values dynamically.

    I’ve looked into Multiton binding as it seemed like a type of Singleton-Factory that would allow the arguments to be changed. But I had no luck with that.

    Here is my Api singleton:

    interface LoginApi {
    
        @POST("Account/Login")
        @FormUrlEncoded
        fun login(
            @Field("username") username: String,
            @Field("password") password: String,
            @Field("sessionType") sessionType: String
        ): Call<BaseApiResponse<Login>>
    
        @GET("Account/Logout")
        fun logout(
            @Query("token") token: String
        ): Call<BaseApiResponse<Any>>
    
        companion object {
            operator fun invoke(
                baseUrl: String,
                cache: Cache
            ): LoginApi {
    
                val okHttpClient = OkHttpClient.Builder()
                    .cache(cache)
                    .readTimeout(60, TimeUnit.SECONDS)
                    .connectTimeout(60, TimeUnit.SECONDS)
                    .build()
    
                return Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl(baseUrl)
                    .addConverterFactory(JacksonConverterFactory.create())
                    .build()
                    .create(LoginApi::class.java)
            }
        }
    }
    

    Dependency Declaration with muliton (doesn’t work):

         import(androidXModule([email protected]))
    
            bind<Any>() with multiton { baseUrl: String, applicationContext: Context ->
                createLoginApi(baseUrl, applicationContext)
                LoginApi(
                    BuildConfig.BASE_URL,
                    Cache(applicationContext.cacheDir, 10 * 1024 * 102)
                )
            }
    
            bind<LoginDataSource>() with singleton { LoginService(instance()) }
            bind<LoginRepository>() with singleton { LoginRepositoryImpl(instance()) }
            bind() from singleton { LoginViewModelFactory(instance()) }
            bind() from singleton { LoginViewModel(instance()) }
        }
    

    Dependency Declaration with no multiton (works):

        import(androidXModule([email protected]))
    
            bind() from singleton {
                LoginApi(
                    BuildConfig.BASE_URL,
                    Cache(applicationContext.cacheDir, 10 * 1024 * 102)
                )
            }
    
            bind<LoginDataSource>() with singleton { LoginService(instance()) }
            bind<LoginRepository>() with singleton { LoginRepositoryImpl(instance()) }
            bind() from singleton { LoginViewModelFactory(instance()) }
            bind() from singleton { LoginViewModel(instance()) }
        }
    

    Version

        implementation 'org.kodein.di:kodein-di-generic-jvm:6.3.2'
        implementation "org.kodein.di:kodein-di-framework-android-x:6.3.2”
    

    Let me know if you need any other information. This is pretty very simple example -- I’d just like to be able to change parameter values dynamically. If that isn’t possible, then is there any way that would allow me to do such a thing

    Thank you in advance!

    type: question 
    opened by JimVanG 10
  •  Implement KSP to create custom builder giving access to resolved API

    Implement KSP to create custom builder giving access to resolved API

    Example

    @Resolved
    interface MyAppResolver : DIResolver, MyFirstLibResolver {
        @Tag("ABC")
        fun foo(str: String): Foo
    }
    
    @Resolved
    interface MyFirstLibResolver : DIResolver, MySecondLibResolver {
        fun bar(): Bar
    }
    
    @Resolved
    interface MySecondLibResolver: DIResolver {
        fun baz(): Baz
    }
    
    private val appResolver: MyAppResolver = DI.ofMyAppResolver {
        bindSingletonOf(::Bar)
        bind { singleton { new(::Baz) } }
        bindFactory("ABC") { _: String -> Foo(bar()) }
    }
    
    @Test
    fun check_AppResolver() {
        appResolver.check()
        assertNotSame(
            illegal = appResolver.foo("HELLO"),
            actual = appResolver.foo("ROMAIN")
        )
    }
    
    opened by romainbsl 0
  • Problem with

    Problem with "Dependency recursion" and lazy

    class A(
     private val b: Lazy<B>
    )
    
    class B(
     private val a: Lazy<A>
    )
    
    bind<A>() with singleton { A(b=lazy{ instance() }) }
    bind<B>() with singleton { B(a=lazy{ instance() }) }
    

    In this case will be throw exception org.kodein.di.DI$DependencyLoopException: Dependency recursion:. That is incorrect for DI, because lazy must fixing recursion of creation instances.

    opened by vevar 0
  • Kodein 7 typeToken TypeNotPresentException for Android D8 desugared ZonedDateTime

    Kodein 7 typeToken TypeNotPresentException for Android D8 desugared ZonedDateTime

    Android's D8 desugars java.time classes on devices running lower than API 26 and this seems to be tripping up typeToken. Using the erased version in previous versions of Kodein worked fine, as does Kodein 7 when using a device with an API >= 26 (because it doesn't get desugared).

    I am going to test Bind(erased<ZonedDateTime>()) (I will update when I get the results of that).

    java.lang.TypeNotPresentException: Type java.time.ZonedDateTime not present
            at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:75)
            at libcore.reflect.Types.getType(Types.java:56)
            at java.lang.Class.getGenericSuperclass(Class.java:828)
            at org.kodein.type.TypeReference.<init>(typeTokensJVM.kt:54)
            at co.myapp.common.Time_moduleKt$timeModule$1$$special$$inlined$bind$1.<init>(typeTokensJVM.kt:64)
    
    opened by eygraber 1
  • ANR report in the Play Console

    ANR report in the Play Console

    Got an ANR report in the Play Console regarding Kodein. Looks like it may have deadlocked:

    Motorola Moto Z(3) (messi), 3840MB RAM, Android 9

    "main" prio=5 tid=1 Runnable
      | group="main" sCount=0 dsCount=0 flags=0 obj=0x755e2ad8 self=0x72c2214c00
      | sysTid=12562 nice=0 cgrp=default sched=0/0 handle=0x7347bbd548
      | state=R schedstat=( 456449984 1930987920 1036 ) utm=21 stm=23 core=0 HZ=100
      | stack=0x7ff58ab000-0x7ff58ad000 stackSize=8MB
      | held mutexes= "mutator lock"(shared held)
      at java.util.HashMap.put (HashMap.java:611)
      at org.kodein.di.internal.KodeinContainerBuilderImpl.bind (KodeinContainerBuilderImpl.java:176)
      at org.kodein.di.internal.KodeinBuilderImpl$TypeBinder.with (KodeinBuilderImpl.java:20)
      at co.myapp.details_moduleKt$detailsModule$1.invoke (details_moduleKt.java:9)
      at co.myapp.details_moduleKt$detailsModule$1.invoke (details_moduleKt.java:1246)
      at -$$LambdaGroup$ks$NvXjYZzOeLC6KhEs7lg_eUCCIbk.invoke (-.java:1246)
      at org.kodein.di.internal.KodeinBuilderImpl.import (KodeinBuilderImpl.java:51)
      at org.kodein.di.Kodein$Builder$DefaultImpls.import$default (Kodein.java:295)
      at co.myapp.MyApp$kodein$1.invoke (MyApp.java:157)
      at co.myapp.MyApp$kodein$1.invoke (MyApp.java:86)
      at org.kodein.di.internal.KodeinImpl$Companion.newBuilder (KodeinImpl.java:22)
      at org.kodein.di.internal.KodeinImpl$Companion.access$newBuilder (KodeinImpl.java:21)
      at org.kodein.di.internal.KodeinImpl.<init> (KodeinImpl.java:19)
      at org.kodein.di.Kodein$Companion$lazy$1.invoke (Kodein.java:447)
      at org.kodein.di.Kodein$Companion$lazy$1.invoke (Kodein.java:429)
      at kotlin.SynchronizedLazyImpl.getValue (SynchronizedLazyImpl.java:74)
    - locked <0x06eea4a5> (a yd1)
      at org.kodein.di.LazyKodein.getBaseKodein (LazyKodein.java:1)
      at org.kodein.di.LazyKodein.getContainer (LazyKodein.java:31)
      at org.kodein.di.KodeinAwareKt.getDirect (KodeinAwareKt.java:222)
      at co.myapp.AppInitProvider.onCreate (AppInitProvider.java:46)
      at android.content.ContentProvider.attachInfo (ContentProvider.java:1919)
      at android.content.ContentProvider.attachInfo (ContentProvider.java:1894)
      at android.app.ActivityThread.installProvider (ActivityThread.java:6651)
      at android.app.ActivityThread.installContentProviders (ActivityThread.java:6198)
      at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6113)
      at android.app.ActivityThread.access$1200 (ActivityThread.java:213)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1807)
      at android.os.Handler.dispatchMessage (Handler.java:106)
      at android.os.Looper.loop (Looper.java:193)
      at android.app.ActivityThread.main (ActivityThread.java:6936)
      at java.lang.reflect.Method.invoke (Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:870)
    
    opened by eygraber 0
Releases(7.17.0)
  • 7.17.0(Dec 29, 2022)

    • Kotlin 1.8.0
    • Ktor 2.2.1
    • JS: Since Legacy backend as been deprecated, Kodein will only support IR.

    ⚠️ Compose capabilities are disable as the compiler plugin has not been released yet. We should be able to re-enable it in 7.17.1 as soon as a new version of compiler plugin will be released.

    Source code(tar.gz)
    Source code(zip)
  • 7.16.0(Nov 14, 2022)

    • Compose 1.2.1 with Kotlin/JS
    • New multi-binding API (see documentation http://kosi-libs.org/kodein/7.16/core/multi-binding.html)
    val di = DI {
        bindSet<Configuration> {
            add { provider { FooConfiguration() } }
            bind { singleton { BarConfiguration() } }
        }
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 7.15.1(Nov 4, 2022)

    Enable Compose Multiplatform 1.2.0.

    ⚠️ Compose Multiplatform 1.2.0 is not compatible with Kotlin/JS 1.7.20, but you can use it with Kotlin 1.7.10.

    Source code(tar.gz)
    Source code(zip)
  • 7.15.0(Sep 29, 2022)

    • Kotlin 1.7.20

    ⚠️ Compose capabilities are disable as the compiler plugin has not been released yet. We should be able to re-enable it in 7.15.1 as soon as a new version of compiler plugin will be released.

    Source code(tar.gz)
    Source code(zip)
  • 7.15.0-kotlin-1.7.20-RC(Sep 26, 2022)

    ⚠️ Compose capabilities are disable as the compiler plugin has not been released yet. We should be able to re-enable it in 7.15.1 as soon as a new version of compiler plugin will be released.

    Source code(tar.gz)
    Source code(zip)
  • 7.14.0(Jul 18, 2022)

  • 7.13.1(Jul 15, 2022)

  • 7.13.0(Jun 21, 2022)

    CORE: - Kotlin 1.7.0 - Deprecation cycle

    ⚠️ Compose capabilities are disable as the compiler plugin has not been released yet. We will re-enable it in 7.13.1 as soon as a new version of compiler plugin will be released.

    Source code(tar.gz)
    Source code(zip)
  • 7.12(May 31, 2022)

    • CORE

      • Kotlin 1.6.21
      • Constructor reference based binding (#408 thanks to @rocketraman)
      DI {
          bindSingleton { new(::PersonService) }
      }
      
      • Delegate binding (#406)
      DI {
          bindSingleton { Cls() }
          delegate<Cls>().to<Cls>()
      }
      
      • Create modules with delegate (#393)
      val myModule by Module { // implicitly named "myModule"
          bind { singleton { Cls() } }
      }
      
    • KTOR

      • Moved to 2.0: This has no impact for you, all the breaking changes are internals.
    • COMPOSE

      • Upgrade to 1.2.0-alpha01-dev683
    • EXTENSION:

      • Improve ConfigurableDI (#395 & #396)
    • Documentation fixes

    Source code(tar.gz)
    Source code(zip)
  • 7.11(Feb 18, 2022)

    • CORE
      • Documentation improvements (thanks to the contributors!).
      • Deprecation cycle
    • COMPOSE
      • JB Compose 1.1.0 Alpha5
      • Introduce rememberDI Composable function
      • Fix rememberX functions` behavior
      • Update documentation
    Source code(tar.gz)
    Source code(zip)
  • 7.10.0(Dec 19, 2021)

  • 7.9.0(Oct 24, 2021)

  • 7.8.0(Sep 10, 2021)

  • 7.7.0(Aug 12, 2021)

    • CORE
      • Kotlin 1.5.21
    • ANDROID
      • 2 new modules have been created to support ViewModel retrieval with ease (thanks to @carltonwhitehead for his contribution).
        • kodein-di-framework-android-x-viewmodel : Injection and retrieval of plain View Models with by viewModel() delegate.
        • kodein-di-framework-android-x-viewmodel-savedstate : Injection and retrieval of View Models with SavedStateHandle with by viewModelWithSavedStateHandle() delegate.
        • See documentation here.
    • COMPOSE: kodein-di-framework-compose module is now align with the stable version of Compose compiler (compatible with Kotlin 1.5.21)
    Source code(tar.gz)
    Source code(zip)
  • 7.5.1(Jun 3, 2021)

  • 7.6.0(May 21, 2021)

  • 7.5.0(Mar 30, 2021)

    • CORE
      • Direct binding by adding bind(tag: Any?, overrides: Boolean?, createBinding: () -> DIBinding)
        • bind { singleton { Person("Romain") } } is equivalent to bind() from singleton { Person("Romain") }
        • bind<IPerson> { singleton { Person("Romain") } } is equivalent to bind<IPerson>() with singleton { Person("Romain") }
        • bind { scoped(SessionScope).singleton { Person("Romain") } } is equivalent to bind() with scoped(SessionScope).singleton { Person("Romain") }
        • etc.
      • Simplified binding APIs
        • bindFactory / bindProvider / bindSingleton / bindMultiton / bindInstance / bindConstant
        • bindSingleton { Person("Romain") } is equivalent to bind() from singleton { Person("Romain") }
        • bindSingleton<IPerson> { Person("Romain") } is equivalent to bind<IPerson>() with singleton { Person("Romain") }
        • etc.
      • Documentation
    • FRAMEWORK
      • Adding Compose support for both Android (Jetpack) and Desktop (JetBrains).
    • Android
      • Deprecate functions di() in favor of closestDI() to avoid import conflicts
    • Ktor
      • Deprecate functions di() in favor of closestDI() to avoid import conflicts
    Source code(tar.gz)
    Source code(zip)
  • 7.4.0(Feb 27, 2021)

  • 7.3.1(Feb 8, 2021)

  • 7.3.0(Feb 5, 2021)

  • 7.2.0(Dec 28, 2020)

  • 7.1.0(Sep 18, 2020)

    • DOCUMENTATION

      • New documentation format https://docs.kodein.org/kodein-di/7.1/
        • Split full documentation into chapters
    • CORE

      • Kotlin 1.4.0
      • Explicit public API mode
      • Fixed possible memory leak with DI context
      • Deprecation cycle
    • BUILD

      • Gradle 6.5.1
      • New Internal Gradle Plugin
      • New snapshot workflow
    Source code(tar.gz)
    Source code(zip)
  • 7.0.0(May 25, 2020)

    • DOCUMENTATION

      • Updated http://kodein.org/Kodein-DI/
        • New type system
        • Module refactoring
        • Code refactoring
      • Migration from version 6 to 7: http://kodein.org/Kodein-DI/?7.0/migration-6to7
    • CORE

      • Modules refactoring: org.kodein.di.generic-jvm / org.kodein.di.erased combined into org.kodein.di
      • New type system with typeOf to handle generics, for non JVM targets only.
      • Package deprecation: org.kodein.di.generic, org.kodein.di.erased.
      • Internals: non nullable context types / test re-organization
      • Deprecation cycle
    • FRAMEWORKS

      • Android / Ktor / TornadoFX : Migration from 6 to 7
    • DEMOS

    • BUILD

      • Gradle 6.3
      • New Internal Gradle Plugin
      • Github Actions
    Source code(tar.gz)
    Source code(zip)
Lightweight, minimalistic dependency injection library for Kotlin & Android

‼️ This project is in maintenance mode and not actively developed anymore. For more information read this statement. ‼️ Katana Katana is a lightweight

REWE Digital GmbH 179 Nov 27, 2022
Koin - a pragmatic lightweight dependency injection framework for Kotlin

What is KOIN? - https://insert-koin.io A pragmatic lightweight dependency injection framework for Kotlin developers. Koin is a DSL, a light container

insert-koin.io 7.8k Jan 8, 2023
Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 6 and above, brought to you by Google.

Guice Latest release: 5.0.1 Documentation: User Guide, 5.0.1 javadocs, Latest javadocs Continuous Integration: Mailing Lists: User Mailing List Licens

Google 11.7k Jan 1, 2023
:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android

Transfuse Transfuse is a Java Dependency Injection (DI) and integration library geared specifically for the Google Android API. There are several key

John Ericksen 224 Nov 28, 2022
The dependency injection Dagger basics and the concepts are demonstrated in different branches

In this project we will look at the dependency injection Dagger basics and the concepts are demonstrated in different branches What is an Dependency?

Lloyd Dcosta 6 Dec 16, 2021
A multi-purpose library containing view injection and threading for Android using annotations

SwissKnife A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and An

Jorge Martin Espinosa 251 Nov 25, 2022
A SharedPreference "injection" library for Android

PreferenceBinder A SharedPreferences binding library for Android. Using annotation processing, this library makes it easy to load SharedPreferences va

Denley Bihari 232 Dec 30, 2022
A fast dependency injector for Android and Java.

Dagger A fast dependency injector for Java and Android. Dagger is a compile-time framework for dependency injection. It uses no reflection or runtime

Google 16.9k Jan 5, 2023
A fast dependency injector for Android and Java.

Dagger 1 A fast dependency injector for Android and Java. Deprecated – Please upgrade to Dagger 2 Square's Dagger 1.x is deprecated in favor of Google

Square 7.3k Jan 5, 2023
DependencyProperty is a dependency resolution library by Delegated Property.

DependencyProperty is a dependency resolution library by Delegated Property. Overview DependencyProperty is simple in defining and

wada811 10 Dec 31, 2022
A sample Grocery Store app built using the Room, MVVM, Live Data, Rx Java, Dependency Injection (Kotlin Injection) and support Dark Mode

Apps Intro A sample Grocery Store app built using the Room, MVVM, Live Data, Rx Java, Dependency Injection (Kotlin Injection) and support Dark Mode In

Irsyad Abdillah 25 Dec 9, 2022
Android library project that lets you manage the location updates to be as painless as possible

Smart Location Library Android library project that intends to simplify the usage of location providers and activity recognition with a nice fluid API

Nacho Lopez 1.6k Dec 29, 2022
An ORM for Android with type-safety and painless smart migrations

Android Orma Orma is a ORM (Object-Relation Mapper) for Android SQLiteDatabase. Because it generates helper classes at compile time with annotation pr

The Maskarade project 440 Nov 25, 2022
Add Animatable Material Components in Android Jetpack Compose. Create jetpack compose animations painless.

AnimatableCompose Add Animatable Material Components in Android Jetpack Compose. Create jetpack compose animation painless. What you can create from M

Emir Demirli 12 Jan 2, 2023
A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.

Toothpick (a.k.a T.P. like a teepee) Visit TP wiki ! What is Toothpick ? Toothpick is a scope tree based Dependency Injection (DI) library for Java. I

Stéphane Nicolas 1.1k Jan 1, 2023
Lightweight, minimalistic dependency injection library for Kotlin & Android

‼️ This project is in maintenance mode and not actively developed anymore. For more information read this statement. ‼️ Katana Katana is a lightweight

REWE Digital GmbH 179 Nov 27, 2022
Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Anna Zharkova 32 Nov 10, 2022
Koin - a pragmatic lightweight dependency injection framework for Kotlin

What is KOIN? - https://insert-koin.io A pragmatic lightweight dependency injection framework for Kotlin developers. Koin is a DSL, a light container

insert-koin.io 7.8k Jan 8, 2023
Lightweight Kotlin DSL dependency injection library

Warehouse DSL Warehouse is a lightweight Kotlin DSL dependency injection library this library has an extremely faster learning curve and more human fr

Osama Raddad 18 Jul 17, 2022