Constructor dependency injection for Kodein.

Overview

kodeinject Build Status Maven Central

A small library allowing constructor dependency injection for applications using Kodein.

Usage

Add dependency

Maven
<dependency>
    <groupId>pw.kmpgroupId>
    <artifactId>kodeinjectartifactId>
    <version>1.2.2version>
dependency>
Gradle
compile "pw.kmp:kodeinject:1.2.2"

Injected

() }">
class Application(db: Database) {
    // stuff goes here
}

val kodein = Kodein {
    bind<Database>() with singleton { MongoDB("127.0.0.1", 27017) }
    bind() from injected<Application>()
}

kodeinject will automatically instantiate your injected() classes using bindings from the Kodein container.

Singleton

val kodein = Kodein {
    bind() from injectedSingleton<Application>()
}

Use injectedSingleton() to cache the dependency instead of creating a new instance for each access.

Nullable

class Application(db: Database, cache: Cache?) {
    // stuff goes here
}

Paramaters that are nullable will be set to null if they are unavailable upon injection.

Automatic Kodein injection

class Application(kodein: Kodein) {
    // stuff goes here
}

Constructors requiring the Kodein object will be injected with it by default, without the need to create a binding.

Comments
  • This appears to only support direct binding, and not as subclass

    This appears to only support direct binding, and not as subclass

    Not sure how this works in Kodein, but if you bind to the Concrete Class for example, and the constructor accepts the implemented Interface, your type check is == so will not bind. Is there an internal call you can make to Kodein to have it do the same logic it would apply?

    Basically calling its instance<type>()?

    wontfix 
    opened by apatrida 2
  • Respect constructor parameters that have default values if missing from bindings

    Respect constructor parameters that have default values if missing from bindings

    Some constructor parameters have default bindings, if those are absent from injection they constructor can still be called using callBy via Kotlin Reflection instead of newInstance via Java reflection.

    enhancement 
    opened by apatrida 1
  • Inject `kodein: Kodein` parameters that constructors will crave

    Inject `kodein: Kodein` parameters that constructors will crave

    Some constructors will accept a kodein because they are KodeinAware, it isn't clear that this works here (it isn't in the bindings, but it is available when you are building a binding).

    enhancement 
    opened by apatrida 1
  • Bump kotlin-stdlib from 1.2.10 to 1.6.0

    Bump kotlin-stdlib from 1.2.10 to 1.6.0

    Bumps kotlin-stdlib from 1.2.10 to 1.6.0.

    Release notes

    Sourced from kotlin-stdlib's releases.

    Kotlin 1.6.0

    Changelog

    Android

    • KT-48019 Bundle Kotlin Tooling Metadata into apk artifacts
    • KT-47733 JVM / IR: Android Synthetic don't generate _findCachedViewById function

    Compiler

    New Features

    • KT-47984 In-place arguments inlining for @​InlineOnly functions
    • KT-12794 Allow runtime retention repeatable annotations when compiling under Java 8
    • KT-43714 Support annotations on class type parameters (AnnotationTarget.TYPE_PARAMETER)
    • KT-45949 Kotlin/Native: Improve bound check elimination
    • KT-43919 Support loading Java annotations on base classes and implementing interfaces' type arguments
    • KT-48194 Try to resolve calls where we don't have enough type information, using the builder inference despite the presence of the annotation
    • KT-47736 Support conversion from regular functional types to suspending ones in JVM IR
    • KT-39055 Support property delegate created via synthetic method instead of field

    Performance Improvements

    • KT-45185 FIR2IR: get rid of IrBuiltIns usages
    • KT-47918 JVM / IR: Performance degradation with const-bound for-cycles
    • KT-33835 Bytecode including unnecessary null checks for safe calls where left-hand side is non-nullable
    • KT-41510 Compilation of kotlin html DSL is still too slow
    • KT-48211 We spend a lot of time in ExpectActual declaration checker when there is very small amount of actual/expect declaration
    • KT-39054 Optimize delegated properties which call get/set on the given KProperty instance on JVM
    • KT-46615 Don't generate nullability assertions in methods for directly invoked lambdas

    Fixes

    • KT-49613 JVM / IR: "Exception during IR lowering" with java fun interface and it's non-trivial usage
    • KT-49548 "ClassCastException: java.util.ArrayList$Itr cannot be cast to kotlin.collections.IntIterator" with Iterable inside let
    • KT-22562 Deprecate calls to "suspend" named functions with single dangling lambda argument
    • KT-47120 JVM IR: NoClassDefFoundError when there are an extension and a regular function with the same name
    • KT-49477 Has ran into recursion problem with two interdependant delegates
    • KT-49442 ClassCastException on reporting [EXPOSED_FROM_PRIVATE_IN_FILE] Deprecation: private-in-file class should not expose 'private-in-class'
    • KT-49371 JVM / IR: "NoSuchMethodError" with multiple inheritance
    • KT-44843 PSI2IR: "org.jetbrains.kotlin.psi2ir.generators.ErrorExpressionException: null: KtCallExpression" with delegate who has name or parameter with the same name as a property
    • KT-49294 Turning FlowCollector into 'fun interface' leads to AbstractMethodError
    • KT-18282 Companion object referencing it's own method during construction compiles successfully but fails at runtime with VerifyError
    • KT-25289 Prohibit access to class members in the super constructor call of its companion and nested object
    • KT-32753 Prohibit @​JvmField on property in primary constructor that overrides interface property
    • KT-43433 Suspend conversion is disabled message in cases where it is not supported and quickfix to update language version is suggested
    • KT-49399 Building repeatable annotation with Container nested class fails with ISE: "Repeatable annotation class should have a container generated"
    • KT-49209 Default upper bound for type variables should be non-null
    • KT-49335 NPE in RepeatedAnnotationLowering.wrapAnnotationEntriesInContainer when using @Repeatable annotation from different file
    • KT-48876 java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl@4a729df2

    ... (truncated)

    Changelog

    Sourced from kotlin-stdlib's changelog.

    1.6.0

    Android

    • KT-48019 Bundle Kotlin Tooling Metadata into apk artifacts
    • KT-47733 JVM / IR: Android Synthetic don't generate _findCachedViewById function

    Compiler

    New Features

    • KT-47984 In-place arguments inlining for @​InlineOnly functions
    • KT-12794 Allow runtime retention repeatable annotations when compiling under Java 8
    • KT-43714 Support annotations on class type parameters (AnnotationTarget.TYPE_PARAMETER)
    • KT-45949 Kotlin/Native: Improve bound check elimination
    • KT-43919 Support loading Java annotations on base classes and implementing interfaces' type arguments
    • KT-48194 Try to resolve calls where we don't have enough type information, using the builder inference despite the presence of the annotation
    • KT-47736 Support conversion from regular functional types to suspending ones in JVM IR
    • KT-39055 Support property delegate created via synthetic method instead of field

    Performance Improvements

    • KT-45185 FIR2IR: get rid of IrBuiltIns usages
    • KT-47918 JVM / IR: Performance degradation with const-bound for-cycles
    • KT-33835 Bytecode including unnecessary null checks for safe calls where left-hand side is non-nullable
    • KT-41510 Compilation of kotlin html DSL is still too slow
    • KT-48211 We spend a lot of time in ExpectActual declaration checker when there is very small amount of actual/expect declaration
    • KT-39054 Optimize delegated properties which call get/set on the given KProperty instance on JVM
    • KT-46615 Don't generate nullability assertions in methods for directly invoked lambdas

    Fixes

    • KT-49613 JVM / IR: "Exception during IR lowering" with java fun interface and it's non-trivial usage
    • KT-49548 "ClassCastException: java.util.ArrayList$Itr cannot be cast to kotlin.collections.IntIterator" with Iterable inside let
    • KT-22562 Deprecate calls to "suspend" named functions with single dangling lambda argument
    • KT-47120 JVM IR: NoClassDefFoundError when there are an extension and a regular function with the same name
    • KT-49477 Has ran into recursion problem with two interdependant delegates
    • KT-49442 ClassCastException on reporting [EXPOSED_FROM_PRIVATE_IN_FILE] Deprecation: private-in-file class should not expose 'private-in-class'
    • KT-49371 JVM / IR: "NoSuchMethodError" with multiple inheritance
    • KT-44843 PSI2IR: "org.jetbrains.kotlin.psi2ir.generators.ErrorExpressionException: null: KtCallExpression" with delegate who has name or parameter with the same name as a property
    • KT-49294 Turning FlowCollector into 'fun interface' leads to AbstractMethodError
    • KT-18282 Companion object referencing it's own method during construction compiles successfully but fails at runtime with VerifyError
    • KT-25289 Prohibit access to class members in the super constructor call of its companion and nested object
    • KT-32753 Prohibit @​JvmField on property in primary constructor that overrides interface property
    • KT-43433 Suspend conversion is disabled message in cases where it is not supported and quickfix to update language version is suggested
    • KT-49399 Building repeatable annotation with Container nested class fails with ISE: "Repeatable annotation class should have a container generated"
    • KT-49209 Default upper bound for type variables should be non-null
    • KT-49335 NPE in RepeatedAnnotationLowering.wrapAnnotationEntriesInContainer when using @Repeatable annotation from different file
    • KT-48876 java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl@4a729df2
    • KT-48131 IAE "Repeatable annotation container value must be a class reference" on using Kotlin-repeatable annotation from dependency

    ... (truncated)

    Commits
    • 829d1d8 Add changelog for 1.6.0
    • 99b69ae Merge KT-MR-4942: Mark packages for relocation to fix classpath interferring ...
    • 583488e [scripting] Fix NPE in aether.kt
    • 0d1f362 Fix PureAndroidAndJavaConsumeMppLibIT working with test project
    • 46af453 JVM KT-49613 don't generate indy reference to protected constructor
    • d5275aa Mark packages for relocation to fix classpath interferring in main-kts
    • a3820d4 JVM KT-49548 progression iterators can be tainted
    • 63044b1 Update -Xjvm-default description
    • e8e3c72 Update INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER message
    • ddd02fe JvmDefault. Allow non default inheritance with special flag
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump junit from 4.12 to 4.13.1

    Bump junit from 4.12 to 4.13.1

    Bumps junit from 4.12 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Kailan Blanks
Developer Relations at Fastly
Kailan Blanks
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
Dependency Injection library for Compose Multiplatform, Koin wrapper.

?? Cokoin Injection library for Compose (Multiplatform and Jetpack), Koin wrapper. It uses @Composable functions to configure KoinContext and Scopes.

Bruno Wieczorek 57 Dec 29, 2022
🍭 GithubSearchKMM - Github Repos Search - Android - iOS - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture

GithubSearchKMM Github Repos Search - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Depend

Petrus Nguyễn Thái Học 50 Jan 7, 2023
Boilerplate code for implementing MVVM in Android using Jetpack libraries, coroutines, dependency injection and local persistance

MVVM Foundation This projects aims to speed up development of Android apps by providing a solid base to extend Libraries Jetpack Fragment Material3 :

Gabriel Gonzalez 2 Nov 10, 2022
View "injection" library for Android.

Kotter Knife Deprecated: This was a terrible idea because it allocates an object for every view reference. Do not use, and do not use anything like it

Jake Wharton 2.2k Dec 28, 2022
Automatic CoroutineDispatcher injection and extensions for kotlinx.coroutines

Dispatch Utilities for kotlinx.coroutines which make them type-safe, easier to test, and more expressive. Use the predefined types and factories or de

Rick Busarow 132 Dec 9, 2022
A injection minecraft cheat using jvm attach api

Luminous A injection minecraft cheat using jvm attach api Website: https://lumi.getfdp.today Build We used a thing called Wrapper to make development

null 24 Dec 21, 2022
A composite Github Action to execute the Kotlin Script with compiler plugin and dependency caching!

Kotlin Script Github Action Kotlin can also be used as a scripting language, which is more safer, concise, and fun to write than bash or python. Githu

Suresh 9 Nov 28, 2022
Actions are things that run, with parameters. Serves as a common dependency for a variety of Cepi extensions.

Actions Actions that take in customizable paramaters, an optional target, and do things. Installation Download the jar from Releases OR compile it you

Cepi 1 Jan 9, 2022
PackageReferenceComparison - Do app/module dependencies that share a dependency use the same Singleton ref?

PackageReferenceComparison Do app/module dependencies that share a dependency us

Liam Niehus-Staab 0 Feb 3, 2022
How to structure a growing Gradle project with smart dependency management?

How to set up a larger Gradle project This repo shows one possibility to structure a Gradle project when you want: Centralized and maintainable build

Jendrik Johannes 59 Jan 6, 2023
Kodein-DB is a Kotlin/Multiplatform embedded NoSQL database that works on JVM, Android, Kotlin/Native and iOS.

Kodein-DB is a Kotlin/Multiplatform embedded NoSQL database that works on JVM, Android, Kotlin/Native and iOS. It is suited for client or mobile applications.

null 277 Dec 3, 2022
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
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
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
: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
Built with Jetpack compose, multi modules MVVM clean architecture, coroutines + flow, dependency injection, jetpack navigation and other jetpack components

RickAndMortyCompose - Work in progress A simple app using Jetpack compose, clean architecture, multi modules, coroutines + flows, dependency injection

Daniel Waiguru 9 Jul 13, 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
Painless Kotlin Dependency Injection

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

null 2.9k Jan 1, 2023
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