https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kodein
  • s

    salomonbrys

    01/07/2019, 4:21 PM
    @obobo No, there's no way. And there won't, because Kodein cannot possibly call all bindings with all configurations.
    o
    • 2
    • 8
  • i

    ian.shaun.thomas

    02/06/2019, 6:31 PM
    do you publish release notes anywhere @salomonbrys?
    s
    d
    r
    • 4
    • 7
  • y

    yshrsmz

    02/20/2019, 1:45 AM
    For me it feels like the behaviour of JS/Native is natural, as you declared
    logger
    as CommonLogger. And in general depending on concrete class is anti-pattern, so if I were you I would bind to
    CommonLogger
    in JVM.
    u
    • 2
    • 10
  • j

    Jorge Castillo

    03/12/2019, 10:44 AM
    @salomonbrys, is Kodein usable just in library modules? I’ve integrated it just in a library module but don’t want my app (android) module to know anything about it, since it’d be a library used by third parties. I’m getting this compile time error:
    s
    • 2
    • 67
  • j

    judrummer

    04/01/2019, 6:12 PM
    Hello @salomonbrys. Kodein 6.1.0 compile error in Kotlin 1.3.30-eap-125 as this snippet. Is there any solution to solve this problem?
    kodein_6_1_0_compile_error_kotlin_1_3_30eap125.kt
    s
    • 2
    • 10
  • j

    JoakimForslund

    04/03/2019, 9:26 AM
    If I have created a top level "Application-like" class that gets invoked at start which implements:
    override val kodein = Kodein {
            import(sdkModule)
        }
    which sets up all the binds. Do each class using those binds also need to implement the above snippet to use them? Or is it enough just to do val nameOfVar by instance() ?
    s
    • 2
    • 1
  • m

    mben

    04/10/2019, 8:50 AM
    Hello i just started kotlin native project and wanna know if kodein can be a solution for hybrid DI for ios and android?
    j
    • 2
    • 2
  • m

    mkobit

    04/12/2019, 6:51 PM
    is there a way to retrieve all bindings (like through
    allInstances()
    ) regardless of tag? we have an application that has multiple
    ServerInterceptor
    that gets added to the server right now we have to bind it in basically 2 places 1. where we want to introduce and configure the
    ServerInterceptor
    implementation 2. in the place where we build the
    Server
    instance and provide the multiple
    ServerInterceptor
    it doesn't look like i can have multiple bindings of the same type (even if in separate kodein modules) for example:
    interface MyInterface
    
    class Impl1 : MyInterface
    
    class Impl2(val s: String) : MyInterface
    
    fun main() {
        val kodein = Kodein {
            constant(tag = "String") with "stringy"
            bind<MyInterface>() with singleton { Impl1() }
            bind<MyInterface>() with singleton { Impl2(instance(tag = "String")) }
        }
    
        val all = kodein.direct.allInstances<MyInterface>()
        println(all)
    }
    fails at bin building time with
    org.kodein.di.Kodein$OverridingException: Binding bind<MyInterface>() with ? { ? } must not override an existing binding.
    adding tags
    bind<MyInterface>(tag = "1") with singleton { Impl1() }
            bind<MyInterface>(tag = "2") with singleton { Impl2(instance(tag = "String")) }
    prints an empty list
    []
    i've seen the
    inSet()
    and
    bind() from setBinding<ServerInterceptor>()
    , but that feels a bit odd, because then each module needs to also use
    inSet()
    on the binding what is the best way to handle this if i'm trying to keep the modules separate?
    r
    o
    • 3
    • 8
  • s

    streetsofboston

    04/16/2019, 5:04 PM
    Since Kodein version 6.x we get this error when bindings are examined:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wecenergygroup.wps.debug/com.wec.weenergies.screens.landing.LandingActivity}: org.kodein.di.Kodein$NotFoundException: 3 bindings found that match bind<Context>() with ?<LandingActivity>().? { ? }:
                module Context {
                    bind<Context>() with singleton { Application }
                }
                module WeEnergiesApplication {
                    bind<WeEnergiesApplication>() with singleton { WeEnergiesApplication }
                }
                module ⁣androidModule {
                    bind<Application>() with provider { Application }
                }
    The first two are under our app’s control, the last one is from Kodein’s
    androidModule
    . What would be the ‘best’ way to solve this ambiguity? Using ‘sub-type’ bindings or is there a less verbose way?
    s
    • 2
    • 4
  • h

    hamutarto

    04/23/2019, 12:36 PM
    hey hey! I'm trying to inject the SharedPreferences from the androidCoreModule but i'm getting this error. Do you know why?
    org.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
        Available bindings for this type:
                module ⁣androidModule {
                    bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
                    bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
                }
        Registered in this Kodein container:
    ..
    r
    • 2
    • 14
  • m

    max.denissov

    04/24/2019, 3:25 PM
    Hello! Can anyone help me? I’m working on the kotlin multiplatform (Android/iOS) project and have a problem with DI. Who hase an example of usage kodein in a multiplatform project?
    y
    • 2
    • 2
  • j

    Jan Stoltman

    05/07/2019, 3:22 PM
    Hey, I'm getting an error when trying to use kodein 6.2.0:
    Could not find  org.kodein.di:kodein-di-erased:6.2.0
    It used to work just fine with 6.1.0. Anybody has any idea what might be the cause?
    m
    • 2
    • 2
  • c

    Chih

    05/16/2019, 2:30 AM
    Hello! How do I create a Spring like bean? I don't have an interface to bind with its implementation. I just need the instance available at kodein container. I went through documentation, but I couldn't find anything similar. Thanks in advance!
    r
    • 2
    • 2
  • c

    Chih

    05/18/2019, 9:12 PM
    Why this isn’t working?
    Kodein.Module(name = "web") {
            bind<Controller>(tag = "health") with singleton { HealthController(instance()) }
            bind<Controller>(tag = "user") with singleton { UserController(instance()) }
    
            bind() from singleton { Server(allInstances<Controller>()) }
    }
    class Server(private val routes: List<Controller>)  { ... }
    When I debug
    routes
    , it is an empty list. Thanks in advance!
    r
    • 2
    • 6
  • i

    igor.wojda

    05/24/2019, 3:27 PM
    Is there any better way of using
    kodein
    inside
    ViewHolder
    ?
    class SomeViewHolder(
        view: View,
        val view: View,
        private val data: Boolean,
    ) : RecyclerView.ViewHolder(view) {
    ) : RecyclerView.ViewHolder(view), KodeinAware {
    
        override val kodein by view.kodein()
    
        private val formatter: CurrencyFormatter by instance()
       ….
    }
    y
    • 2
    • 1
  • j

    Joan Colmenero

    06/03/2019, 2:45 PM
    Is this the way to do it? Using
    Dagger2
    I had it divided by modules and I see this like a dirty way to do the dependency injection, is there any other way to do it cleaner?
    s
    r
    • 3
    • 9
  • y

    yahyabayramoglu

    06/18/2019, 4:12 PM
    Hello everyone 👋 Is there a way to add modules later than first kodein object creation? Example case, in Dagger you would create a component by depending on application component (assuming) and add more modules on top and use that to provide / inject. I want to achieve the similar behaviour with Kodein, is there a way to create a kodein instance based on another kodein instance and add more modules on top, for example?
    s
    • 2
    • 2
  • j

    Joan Colmenero

    07/06/2019, 7:14 PM
    @Database(entities = [Something::class], version = 1, exportSchema = false)
    abstract class MyDatabase : RoomDatabase() {
    
        abstract fun myDao(): MyDao
    
        companion object {
    
            @Volatile
            private var INSTANCE: MyDatabase? = null
    
            fun getInstance(context: Context): MyDatabase =
                INSTANCE ?: synchronized(this) {
                    INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
                }
    
            private fun buildDatabase(context: Context) =
                Room.databaseBuilder(
                    context.applicationContext,
                    MyDatabase::class.java, "sample_db"
                )
                    .allowMainThreadQueries()
                    .build()
        }
    
    }
    s
    s
    r
    • 4
    • 27
  • e

    Evan Bennett

    07/09/2019, 6:41 AM
    We have been getting "org.kodein.di.Kodein$DependencyLoopException: Dependency recursion:" errors on and off for a while. We have ended up removing any Kodein access from class initialisation. The Kodein instance is only accessed within functions and inner classes, so we cannot work out how it is causing problems. We are looking for some information about what causes this to occur. To my thinking: * we access the Kodein instance to get an instance (A), which gets initialised, stored (in the Kodein container) and returned * a function (f1) on the returned instance (A) is executed * this function (f1) accesses the Kodein instance to get a different instance (B), which gets initialised, stored and returned * a function (f2) on the new returned instance (B) is executed * this function (f2) accessed the Kodein instance to get the original instance (A) which should already be stored and just be returned
    r
    • 2
    • 5
  • h

    hamutarto

    07/12/2019, 7:30 PM
    hey Guys! I’m struggling with a strange issue! I’m injecting SharedPref all around the app but sometimes, I’m getting this error.
    org.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
        Available bindings for this type:
                module ⁣androidModule {
                    bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
                    bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
                }
        Registered in this Kodein container:
                module analyticsModule {
                    bind<Analytics>() with singleton { AnalyticsImpl }
                }
                ....
                module apiM
    I tried to solve it by manually bind SharedPreferences, without any luck
    bind<SharedPreferences>() with singleton { PreferenceManager.getDefaultSharedPreferences(instance()) }
    but what I eventually do (as I need Android Context as well for injection) is to use androidXmodule in the Application object. However the issue is still coming
    override val kodein = Kodein.lazy {
            import(androidXModule(this@MainApplication))
            import(generalModule)
            import(repositoryModule)
            import(viewModelModule)
            import(appSettingsModule)
            import(apiModule)
            import(useCaseModule)
            import(analyticsModule)
            import(locationModule)
            import(dataSourceModule)
        }
    Please help me! I can’t find the solution
    d
    • 2
    • 10
  • j

    Jan Stoltman

    07/24/2019, 8:10 AM
    Is there a way in Kodein to evaluate all bindings? Eg. at one point I would like to evaluate whether or not all declared bindings can be provided with their required parameters
    s
    i
    • 3
    • 5
  • i

    Ivan

    07/24/2019, 4:24 PM
    Is there a way to get dependency from kodein object on IOS in kotlin/native project?
    y
    • 2
    • 3
  • n

    n0rtan

    07/24/2019, 7:50 PM
    Hi guys... How to run kodein in tornadofx? Demo projeect doesnt work.. https://github.com/Kodein-Framework/Kodein-Samples/tree/master/di/tornadofx
    r
    • 2
    • 7
  • n

    n0rtan

    07/24/2019, 7:59 PM
    working with maven { url "https://dl.bintray.com/kodein-framework/Kodein-DI" } in repositories
    r
    • 2
    • 3
  • g

    Giovani Guerra

    08/01/2019, 6:56 PM
    How to create an android library with kodein? 1 - I want to pass the app context to the library builder and init kodein from there. 2- The application class in sample knows nothing about kodein. How I can achieve this?
    s
    • 2
    • 3
  • a

    Albert

    08/23/2019, 8:20 AM
    I try to create a composite using it like this:
    bind<Action>(tag = "ActionImpl2") with singleton { ActionImpl2() }
    bind<Action>(tag = "ActionImpl2") with singleton { ActionImpl2() }
    bind<Action>() with singleton {
    	CompositeAction(
    			allInstances<Action>()
    	)
    }
    Problem here is that
    allInstances<Action>()
    is causing recursive error, probably because this is lazy loaded. Is it possible to invoke
    allInstances<Action>()
    in such a way that it will exclude it own bind and only loads the
    Action
    instances with a
    tag
    ? Preferably I don't want to eager load.
    s
    • 2
    • 5
  • u

    ushort

    09/03/2019, 1:36 AM
    God lol subtypes is so hard to understand
    r
    • 2
    • 1
  • j

    judrummer

    09/11/2019, 5:33 PM
    @salomonbrys Can you update to use Kotlin 1.3.50 ?
    r
    • 2
    • 4
  • p

    Paulus Limma

    09/16/2019, 5:37 AM
    Hi! Would anybody be able to help me with this problem? https://github.com/Kodein-Framework/Kodein-DI/issues/231
    r
    • 2
    • 2
  • j

    james

    10/03/2019, 3:46 AM
    this is a question from a few months ago that was never answered, and I've just found it because I'm searching for the same thing. does anyone have information about using Android's dynamic feature modules with kodein?
    s
    g
    • 3
    • 3
Powered by Linen
Title
j

james

10/03/2019, 3:46 AM
this is a question from a few months ago that was never answered, and I've just found it because I'm searching for the same thing. does anyone have information about using Android's dynamic feature modules with kodein?
s

salomonbrys

10/04/2019, 8:52 AM
Honnestly, I've never tried android dynamic feature modules. How does it work ? Are they present when the app starts or do they need to be downloaded / loaded at runtime ?
g

ghedeon

10/06/2019, 8:16 AM
The latter, they need to be downloaded. And because there is no direct link to that code from the main app, google proposed to call it via reflection. Apparently it's acceptable now, go figure 🙂.
s

salomonbrys

10/07/2019, 9:02 AM
Well. Then it's kinda complicated. You can't modify a kodein container once it is created, except with ConfigurableKodein : https://kodein.org/Kodein-DI/?6.4/configurable
View count: 3