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
koin
  • z

    zalewski.se

    06/07/2020, 12:51 PM
    Hi! I’m trying to figure out best way to deal with Koin in multi module project… Is there any recommended way? So for example:
    network  <--\              / <-- home   <--\
                 | repository |                 | app
    database <--/              \ <-- login  <--/
    In such scenario (app depends on home&login where home&login depends on repository where repository depends on network… etc, depends on mean using
    implementation
    , not
    api
    ), how to manage Koin modules? I was thinking of having network provide it’s own modules and passing it up to repository, repository would consume it, add it’s own and pass it up further.. This will cause the problem where many network and repository koin modules would be provided to the app module (I know I can fix it by allowing overriding the modules) . It’s also not so flexible for testing, I can’t provide testNetwork module in home or login feature as these modules are unaware of the network. Another thing is that I can’t really test database as it’s needs to be aware of Android context (sqldelight..) so to test checkModules configuartion I would need to mock it there. Different idea I had was to create another module like
    di
    that would be aware of all the modules that expose some Koin modules. In
    di
    I would connect everything together and expose it for the app module (which would depend on
    di
    ). But this doesn’t really solves the problem with testing 🤔
    d
    y
    • 3
    • 9
  • v

    voben

    06/08/2020, 11:54 PM
    I essentially need a navGraphSavedStateViewModel. Any ideas?
    m
    • 2
    • 1
  • e

    Egor Babarykin

    06/11/2020, 12:32 PM
    Hi Is there any possibility to use profiles (such as spring) to enable/disable some beans in module And is there analog of spring @PostConstruct ?
    a
    • 2
    • 2
  • a

    Allan Wang

    06/17/2020, 9:29 AM
    Has anyone experienced flaky tests without output
    java.lang.IllegalStateException at KoinContextHandler.kt
    From
    ./gradlew testDebug
    ? I’ve used koin before in a few projects and this one is internal. It extends
    AutoCloseKoinTest
    and fails for certain files exactly every other time. Using
    ./gradlew clean testDebug
    fixes it, but I’m not sure what the issue is. Curious if anyone has experienced the same thing
    t
    a
    • 3
    • 6
  • s

    Santosh Astagi

    06/19/2020, 1:43 PM
    ( New to koin here ) I have started koin in my Application in Android, and am now trying to override a network dependency in the unit tests, but am having trouble doing so. I have tried setting that network component as override and using loadKoinModule, but get an error, please use startKoin
    t
    • 2
    • 2
  • s

    streetsofboston

    06/19/2020, 7:04 PM
    When binding two singletons like this:
    single { SomeClass.Factory(...) }
    single { SomeOtherClass.Factory(...) }
    (on Kotlin Multi Platform), I get this error:
    java.lang.IllegalStateException: InstanceRegistry already contains index 'Factory'
    How can I make Koin use the qualified class name instead of just the inner class’ name? It is probably of this code in the jvm target of Koin:
    actual fun className(kClass: KClass<*>): String = kClass.java.simpleName
    Why is
    simpleName
    used and not the full-name?
    k
    • 2
    • 2
  • p

    ParkWoocheol

    06/22/2020, 6:49 AM
    hi I use proguard but E/[Koin]: Instance creation error : could not create instance for [Factory:'d0.z']: f0.b.c.i.f: No definition found for class:'d0.l0.a'. Check your definitions E/[Koin]: Instance creation error : could not create instance for [Single:'h.a.a.a.a.k.z']: f0.b.c.i.d: Could not create instance for [Single:'g0.f0'] ...... Caused by: f0.b.c.i.f: No definition found for class:'d0.l0.a'. Check your definitions! .... I want to solve it.
    z
    • 2
    • 3
  • d

    Deepti M

    06/24/2020, 9:16 PM
    Hi There, I am receiving following exception in some devices, can anyone help me to resolve? Fatal Exception: java.lang.RuntimeException Unable to start activity ComponentInfo{com.alivewallpaper.free/com.alivewallpaper.replicantlib.MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase'] Precised logs:
    Fatal Exception: java.lang.RuntimeException
    Unable to start activity ComponentInfo{MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase']
    android.app.ActivityThread.performLaunchActivity
    keyboard_arrow_down
     
    Caused by org.koin.core.error.InstanceCreationException
    Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase']
    org.koin.core.instance.InstanceFactory.a
    keyboard_arrow_down
     
    Caused by com.google.firebase.database.DatabaseException
    Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance
    t
    • 2
    • 5
  • s

    Sean McQuillan [G]

    06/29/2020, 6:40 PM
    If that inject call is non-idempotent, it likely should be wrapped in a lifecycle effect like this:
    @Composable
    fun <T> koinInject(): T {
        val context = KoinContext.get() // this won't recompose if KoinContext is changable, if that is so this should become an Ambient
        return remember(context) { context.inject() } // inject only called once per component per context (but doesn't trigger recomposition when context changes)
    }
    Wanted to post it here to see what the requirements are. Code like this would make it behave similarly to a member variable.
    a
    h
    k
    • 4
    • 16
  • a

    Abhishek Bansal

    07/06/2020, 10:27 AM
    In our app Koin overshadows actual crash log in Crashlytics. Is there a solution to this. We get crash logs like this instead of actual crashes
    Caused by k.a.c.f.e: No definition found for '<package>.h' has been found. Check your module definitions.
           at org.koin.core.scope.Scope.findDefinition(Scope.java:52)
           at org.koin.core.scope.Scope.resolveInstance(Scope.java)
           at org.koin.core.scope.Scope.get(Scope.java:123)
           at org.koin.androidx.viewmodel.ViewModelResolutionKt$createViewModelProvider$1.create(ViewModelResolutionKt.java:25)
           at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:37)
           at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:23)
           at org.koin.androidx.viewmodel.ViewModelResolutionKt.getInstance(ViewModelResolutionKt.java:119)
           at org.koin.androidx.viewmodel.ViewModelResolutionKt.getViewModel(ViewModelResolutionKt.java:26)
    This even happens in local testing
    t
    • 2
    • 5
  • n

    Nikola Milovic

    07/07/2020, 4:15 PM
    Any more active communities for Koin? 😂 Besides that, any multi-module clean architecture projects with Koin that I can check out? I've seen some articles but havent had luck with projects
    a
    • 2
    • 2
  • h

    Hakob Astvacatryan

    07/07/2020, 8:13 PM
    Hi guys, thinking about to have activity scope with view model that doesn’t get destroyed when rotation changed, is it possible?
    v
    • 2
    • 1
  • n

    Nikola Milovic

    07/13/2020, 4:57 PM
    Hey guys, I am I doing this wrongly or? I have a single activity approach with multi feature modules with their fragments and VM's. Now I have a DI package in my Module A with repository, network and VM koin modules. This is what I am doing at the moment. I just reference those 3 modules from the other package.
    open class App : Application() {
    
        override fun onCreate() {
            super.onCreate()
            startKoin {
                // Android context
                androidContext(this@App)
                // modules
                modules(com.example.core.di.networkModule, (com.example.homeFeed.di.)viewModelModule, (com.example.homeFeed.di.)repositoryModule, com.example.homeFeed.di.networkModule)
            }
        }
    
    }
    But I crash with this as the output https://hastebin.com/qizixidumu.sql Also is there a better way to handle koin modules in a multimodule app? Like having an array of modules and then just loading them when needed as the fragments change? Thank you!
    a
    • 2
    • 9
  • a

    Allan Wang

    07/13/2020, 7:11 PM
    Does
    checkModules
    test viewModel modules? I’m having an issue with resolving a class that has a provider, and after commenting things out I realize none of the viewModel providers seem to be tested
    v
    • 2
    • 3
  • z

    zsperske

    07/15/2020, 5:40 PM
    Is anyone here using Koin in their Kotlin Multiplatform project? How are you feeding your swift classes into Koin from your iOS app?
    s
    r
    • 3
    • 26
  • a

    Arpan Sarkar

    07/28/2020, 7:30 PM
    any work around for this https://github.com/InsertKoinIO/koin/issues/830
    a
    • 2
    • 7
  • r

    reevn

    07/29/2020, 3:16 PM
    Hey 👋 Is there any "unload-hooks" functionality one can achieve with Koin? For example: You have some components that need to explicitly clean up and just removing a reference to it is not enough. You could let these components extend an interface that makes it clear that these components need to do clean up (
    class A : Disposable
    ).
    Disposable
    offers a
    dispose
    function that every such component needs to implement. Is there a way to let Koin trigger
    dispose
    of all loaded dependencies once
    unloadModule(...)
    is called?
    a
    • 2
    • 5
  • a

    Alex

    07/30/2020, 4:06 PM
    Hello, I was checking if I could drop jetifier, and I found out that Koin is still using some support libraries. is there any plan to fully migrate to AndroidX in the near future? Thanks
    a
    a
    • 3
    • 3
  • k

    kzotin

    08/03/2020, 9:03 AM
    Hi colleagues, Could you advise please, what's Koin`s official position on injecting on
    @WorkerThread
    thread? (e.g. in
    FirebaseMessagingService
    ) Is it considered OK or discouraged?
    • 1
    • 1
  • f

    Fabio

    08/07/2020, 6:24 AM
    hi, I'm new to
    checkModules
    . As I understand it only checks if there are gaps inside the module graph. But if I try to check for a leaf of the graph it won't fail, such as forgetting to add a
    factory { B() }
    in the following case.
    class A : KoinComponent {
      val b : B by inject()
    }
    class B {
    }
    Is there any way to check for that too without having to write specific tests for specific classes? (which I may forget)
    a
    • 2
    • 11
  • g

    gps

    08/10/2020, 11:14 AM
    Hey everyone, cross posting this from #ktor: has anyone tried using Koin with Ktor, and creating a scope that lasts for the duration of a request? For example, if I wanted to be able to inject something like a trace id, how would I go about doing that? Thanks!
    g
    a
    • 3
    • 5
  • a

    arnaud.giuliani

    08/11/2020, 7:40 AM
    Anyone here that would help integrate Koin with Navigation Graph jetpack library?
    t
    h
    • 3
    • 10
  • a

    arnaud.giuliani

    08/19/2020, 8:00 AM
    not yet, work in progress 👍
    j
    • 2
    • 2
  • a

    arnaud.giuliani

    08/19/2020, 8:18 AM
    but then also, a bit of breaking (Scope API mostly)
    o
    a
    • 3
    • 32
  • j

    Javier

    08/19/2020, 8:59 AM
    @arnaud.giuliani is it planned to improve the experimental feature to avoid the usage of
    get()
    ? it is recommended to not use in Android, maybe moving from reflection to some another alternative (arrow meta maybe?)
    a
    h
    f
    • 4
    • 13
  • j

    Javier

    08/20/2020, 1:59 PM
    Is there some doc about Koin 3.0.0 and its usage in multiplatform projects?
    a
    z
    • 3
    • 3
  • a

    arnaud.giuliani

    08/21/2020, 1:31 PM
    Koin 2.2.0-alpha-1 is out ... Now you can use KOin with Kotlin 1.4 👍
    🎉 9
    m
    z
    a
    • 4
    • 12
  • z

    zsperske

    08/27/2020, 2:18 PM
    Sorry to re-ask this but does anyone know if the 3.0.0 branch (for KMP) is going to be updated for 1.4?
    ➕ 1
    a
    • 2
    • 2
  • a

    Abhishek Bansal

    08/29/2020, 6:50 AM
    [Question] what does
    unloadKoinModules
    actually do? What is meant by
    unload Koin modules from global Koin context
    Does it not destroy the instances module contain?
    a
    • 2
    • 1
  • d

    Davide Giuseppe Farella

    08/29/2020, 1:58 PM
    Is there a way to have default params? Let’s say I want to have something like
    factory { MyParams(...) }
    
    factory { (p: MyParams) -> MyClass(param = p) }
    factory { MyClass(param = get() }
    t
    • 2
    • 1
Powered by Linen
Title
d

Davide Giuseppe Farella

08/29/2020, 1:58 PM
Is there a way to have default params? Let’s say I want to have something like
factory { MyParams(...) }

factory { (p: MyParams) -> MyClass(param = p) }
factory { MyClass(param = get() }
t

tynn

08/29/2020, 5:54 PM
Destructuring declarations are nice, but not necessary. Instead you could achieve the same manually using
DefinitionParameters
directly.
View count: 9