https://kotlinlang.org logo
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
  • e

    eurycea

    08/13/2021, 4:03 PM
    To that I'd point to the projects google also no longer supports.
    😂 5
    a
    • 2
    • 1
  • r

    Roman Belousov

    08/17/2021, 8:15 AM
    Hello, I’m trying to use Koin for my multiplatform project. Some of my dependencies has to be registered from iOS side, is there a way to do this? I can’t use module’s
    factory { }
    or
    single { }
    methods because they are reified functions (got exception
    IllegalStateException: unsupported call of reified inlined function
    ). There is a task I created https://github.com/InsertKoinIO/koin/issues/1108 but still no answer.
    a
    • 2
    • 1
  • y

    Yahor

    08/17/2021, 8:17 AM
    @arnaud.giuliani Hello, do you have a roadmap for the new releases?)
    a
    m
    • 3
    • 4
  • w

    wbertan

    08/17/2021, 9:24 AM
    Hello, we are seeing a weird crash using Koin in a KMM project 🤔 We call
    koin.get(objCObject: type) *as*! T
    in Swift and it works, we are calling it in
    SceneDelegate
    willConnectTo
    . When opening the app, all works, putting the app in background, still works, coming back still works. After some time the app in Background, we can see a bunch of crashes in that line on
    SceneDelegate
    trying to
    get
    the dependency. The object I’m trying to get in
    SceneDelegate
    is the
    IsAuthenticatedUseCase
    (hence I’m putting everything it needs to actually creates its own dependencies - in 🧵).
    koin
    is created and started in
    SceneDelegate
    , or the error would be a
    nil
    if it wasn’t.
    Non-fatal Exception: InstanceCreationException
    Could not create instance for [Singleton:'my.package.common.core.authentication.IsAuthenticatedUseCase']
    Sorry for the stacktrace, we are using CrashKiOS to actually be able to see this crash, will post the stacktrace, and definition of dependencies in 🧵
    • 1
    • 2
  • g

    g4sarma

    08/19/2021, 9:27 AM
    Hey guys, i am trying to migrate from V2 to V3 and get rid of the Jcenter dependency in my project. And it seems gradle is not able to recognize the io.insert-koin in my project when trying to import the same in my class. Has anyone faced a similar problem ?
    k
    • 2
    • 4
  • b

    Bradford Canonigo

    08/28/2021, 7:40 AM
    I called
    startKoin
    inside my Application class in Android, and called
    loadKoinModules
    inside the MainActivity after user logged in. Why am I always receiving
    KoinApplicaiton has not been started
    error?
    ł
    a
    • 3
    • 2
  • k

    kevindmoore

    08/30/2021, 5:49 PM
    I might have to remove Koin from my project as I keep getting crashes due to Fragments being reinstantiated. I've put all kinds of code in to check the status and stop/restart koin.
    s
    a
    • 3
    • 31
  • s

    Songv

    08/31/2021, 9:53 AM
    Hi all, I have a config bean and a service bean, the service bean has two impl, I need to choose one service impl to register by the condition(using config to calculate the condition). How can I do? or maybe I can registry them all, and inject by condition, I don’t know how to do in koin also.
    s
    a
    • 3
    • 4
  • o

    Orhan Tozan

    09/02/2021, 2:24 PM
    So what is the recommended way of using Koin with testing? Both documentation pages have different sample code: https://insert-koin.io/docs/reference/koin-test/testing https://insert-koin.io/docs/quickstart/junit-test/ Confusing
    m
    • 2
    • 2
  • m

    Matt Thompson

    09/02/2021, 3:47 PM
    anyone know how to use
    checkModules
    with
    stateViewModel
    ? I was previously getting around it by using `
    create<ViewModelType> { StateDefinitionParameter(SavedStateHandle()) }
    but
    StateDefinitionParameter
    no longer exists
    • 1
    • 2
  • m

    Matthew Laser

    09/02/2021, 8:15 PM
    I know there's the
    get
    from
    KoinJavaComponent
    , but not sure if that is the preferred method for getting on demand instances in Kotlin code
    a
    m
    • 3
    • 4
  • m

    mirland

    09/17/2021, 3:21 PM
    Jetpack ViewModel has a lot of advantages, it's a good state holder because it's aware of the configuration changes and other stuff. Suppose that you have another class, that is not a viewModel, and you want the same behavior. Is it posible using koin? When you're injecting a VM, you are injecting something that has a lifecycle aware scope, so is it possible?
    a
    • 2
    • 6
  • o

    orafaaraujo

    09/22/2021, 1:48 PM
    Hello, I'm having this stacktracke while I'm trying to work with api/impl module
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: ......, PID: 29490
        java.lang.StackOverflowError: stack size 8MB
            at kotlin.reflect.jvm.internal.pcollections.IntTree.get(IntTree.java:93)
            at kotlin.reflect.jvm.internal.pcollections.IntTree.get(IntTree.java:93)
            at kotlin.reflect.jvm.internal.pcollections.IntTreePMap.get(IntTreePMap.java:42)
            at kotlin.reflect.jvm.internal.pcollections.HashPMap.getEntries(HashPMap.java:85)
            at kotlin.reflect.jvm.internal.pcollections.HashPMap.get(HashPMap.java:51)
            at kotlin.reflect.jvm.internal.KClassCacheKt.getOrCreateKotlinClass(kClassCache.kt:32)
            at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.getOrCreateKotlinClass(ReflectionFactoryImpl.java:50)
            at kotlin.jvm.internal.Reflection.getOrCreateKotlinClass(Reflection.java:59)
            at org.koin.android.ext.koin.ModuleExtKt.androidApplication(ModuleExt.kt:54)
    b
    a
    n
    • 4
    • 13
  • c

    chi

    09/27/2021, 10:01 AM
    I'm having issues injecting a scoped dependency into my viewmodel and creating the viewmodel.
    class Cache(sess: SessionManager)
    
    class MyViewModel(cache: Cache): ViewModel {}
    
    module {
       single { SessionManager() }
    
       scope(named("userSession")) {
           scoped { Cache(get()) }
    
           viewModel { MyViewModel(get()) }
       }
    } 
    
    class MyFragment: Fragment() {
        private val myVm: MyViewModel by viewModel()
    }
    The above is the structure of my koin setup but when I run this it crashes my app with the error;
    Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.play.MyViewModel'. Check your definitions!
    Please what could I be doing wrongly here?
    a
    • 2
    • 10
  • g

    George Theocharis

    09/28/2021, 8:29 AM
    Hey all! Most probably it wont be koin but as I am losing my mind here goes. After updating koin to 3.1.2 google maps are not visible. Do you think it can be something koin related? In the commit we "lose" the maps the only thing changed is the koin version. Although koin seems to be working as it injects stuff correctly.
    a
    • 2
    • 3
  • v

    Vivek Modi

    09/28/2021, 11:34 AM
    Hey i am using
    koin 2.2.2
    whenerver i used any object class and inject through koin and used that object class in any other class like view holder it gives warning. How to avoid this warning
    🙌 1
    b
    a
    • 3
    • 11
  • s

    Scott Kruse

    10/15/2021, 4:29 AM
    Is compose multiplatform supported by Koin multiplatform?
    m
    • 2
    • 1
  • s

    Sam

    10/19/2021, 3:56 AM
    Hello everyone, I have read this article about performance of
    Koin
    Ref: https://proandroiddev.com/how-dagger-hilt-and-koin-differ-under-the-hood-c3be1a2959d7 Im curious, How can I calculate the performance of Koin in Runtime like this articles? Thanks.
    e
    a
    m
    • 4
    • 17
  • m

    Merseyside

    10/21/2021, 8:51 AM
    Hi! How can I add an instance to navGraph scope and provide it in fragment's ViewModels inside this navGraph? it's ok with shared ViewModel in navGraph, but how to use it with usual intances?
    a
    • 2
    • 1
  • c

    Chris

    10/25/2021, 8:54 AM
    Hi … I have a question about migration from koin 2.x to 3.x In my fragment I use something like this
    val viewModel by getScope("user-session").viewModel<Class>(owner = this)
    this works fine at least for koin 2.x. What happens in getscope() is it check it this scope is there or creates a new one of user-session. So that the viewmodel is bound to the user-session scope. For koin 3.x I have to add more complex implementation
    val viewModel by getScope("user-session").viewModel<Class>(owner = {ViewModelOwner.from(findNavController().getViewModelStoreOwner(R.id.graph))})
    is this the way to go or is there a better solution for ? Thanks in advance
    a
    • 2
    • 3
  • m

    Matthew Laser

    10/26/2021, 2:24 PM
    does anyone know if it's possible to inject into an android
    JobService
    ? It's an extension of
    Service
    so it seems like Koin should support it in the way that
    Activity
    and
    Fragment
    are (by being able to simply use
    by inject<MyClass>()
    ) but it's not working as I'd expect
    this works fine!
    a
    • 2
    • 4
  • a

    ABRAR WIRYAWAN

    10/31/2021, 2:43 PM
    Hi, i want to ask about what is "with" in this context? I mean, added with what? Thanks before
    a
    • 2
    • 2
  • a

    arnaud.giuliani

    11/02/2021, 10:30 AM
    Hi all, here is the Koin 3.1.3 changelog - https://github.com/InsertKoinIO/koin/blob/master/CHANGELOG.md#313
    :kotlin-intensifies: 2
    👍 4
    h
    • 2
    • 1
  • e

    Eric Martori

    11/02/2021, 1:20 PM
    We are having an issue since we updated from the version 2.X to 3.1.3 in our Android App: Crashlytics is reporting that about 5% users are having the following crash:
    Caused by java.util.NoSuchElementException
    ArrayDeque is empty.
    org.koin.core.scope.Scope.resolveInstance (Scope.kt:213)
    org.koin.core.scope.Scope.get (Scope.kt:193)
    org.koin.androidx.viewmodel.factory.DefaultViewModelFactory.create (DefaultViewModelFactory.kt:11)
    androidx.lifecycle.ViewModelProvider.get (ViewModelProvider.java:187)
    androidx.lifecycle.ViewModelProvider.get (ViewModelProvider.java:150)
    org.koin.androidx.viewmodel.ViewModelResolverKt.get (ViewModelResolver.kt:23)
    org.koin.androidx.viewmodel.ViewModelResolverKt.resolveInstance (ViewModelResolver.kt:12)
    org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel (ScopeExt.kt:86)
    org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel (ScopeExt.kt:72)
    org.koin.androidx.viewmodel.ext.android.ViewModelStoreOwnerExtKt.getViewModel (ViewModelStoreOwnerExt.kt:68)
    But we are unable to reproduce the issue and haven't seen it in over 2 weeks of testing. I've seen that there is an open issue that seems related to this: https://github.com/InsertKoinIO/koin/issues/1149 But we are no using the
    getOrNull
    method that the tickets seems to imply is the cause of the issue. Is there anything (besides downgrading or waiting for a fix) that we can do? Does anyone know a way we could try and reproduce the issue in a consistent manner or why is it so hard to reproduce the issue?
    a
    • 2
    • 2
  • a

    aipok

    11/03/2021, 9:44 AM
    does anyone knows why
    factory
    is getting warning
    This API is using reflection and implies some introspection performance penalties on limited capacity devices (Android)
    in 3.1.3? How to fix it?
    a
    • 2
    • 4
  • h

    holgerbrandl

    11/06/2021, 7:19 PM
    Hi there, has anyone tried to persist/unpersist a KoinApplication/Koin instance using https://github.com/EsotericSoftware/kryo? If so, is there some implementation I could recycle?
    a
    • 2
    • 2
  • r

    Rak

    11/08/2021, 3:38 PM
    Hi, I am trying to replace a dependency after Koin has started in my tests. In the docs there is a reference to a
    declare
    method but I cant seem to get it to resolve in the IDE.
    a
    • 2
    • 1
  • l

    Lukasz Kalnik

    11/09/2021, 5:07 PM
    I have an Android/iOS project which has a Koin module in 
    shared
     : CommonModule.kt:
    val commonModule = module {
        single<HttpClient> { TmdbApi.createHttpClient() }
        single<TmdbApi> { TmdbApi(client = get()) }
    }
    
    fun initKoin() = startKoin {
        modules(CommonModule.module)
    }
    In the Android app I can inject dependencies very easily:
    val tmdbApi: TmdbApi by inject()
    In the iOS AppDelegate I call 
    CommonModuleKt.doInitKoin()
    How can I inject the dependencies in the iOS 
    ContentView
    ?
    s
    m
    • 3
    • 8
  • h

    Hakob Astvacatryan

    11/10/2021, 3:39 PM
    Hey folks, we are considering koin as a DI solution for our project. Does anybody experienced issues working with koin in case of multi modular big project(about 30 modules)
    ➕ 1
    w
    • 2
    • 4
  • a

    Alexander Mitropolsky

    11/11/2021, 5:00 PM
    Hi! I noticed that ScopeDLS.viewModel (...) extension uses “scoped” instead of “factory” for the ViewModel definition. This fact may lead to issues if the scope qualifier is different from the ViewModelStoreOwner. Here is an example: Let’s create scopes:
    scope(qualifier<SomeFragment>())
    scope(qualifier<LongLiveScope>()) {
      
    viewModel { SomeViewModel ()}
    }
    Then we link these scopes:
    fragmentScope.linkTo(longLiveScope)
    Then we inject SomeViewModel into SomeFragment with the
    viewModel()
    extension, which uses the ViewModelStore from SomeFragment. When SomeFragment is destroyed, its ViewModelStore is also destroyed, and
    SomeViewModel::onClear
    will be called. However, the SomeViewModel instance will not be destroyed because it is scoped in LongLiveScope, which leads to issues when the same (already cleared) instance of SomeViewModel is reused in new fragments. For example, ViewModel’s coroutines scope will not work because it will be already closed after onCleared. I think the ViewModel should be shared using the shared ViewModelStore, but not using the Koin scope, otherwise, it breaks the lifecycle of the ViewModel itself. I hope I explained this issue in sufficient detail. Can you please explain why the ViewModel definition has changed? And what can I do if the ViewModelStoreOwner is different from the scope, other than rolling back the old ViewModel definition? Thank you!
    a
    • 2
    • 3
Powered by Linen
Title
a

Alexander Mitropolsky

11/11/2021, 5:00 PM
Hi! I noticed that ScopeDLS.viewModel (...) extension uses “scoped” instead of “factory” for the ViewModel definition. This fact may lead to issues if the scope qualifier is different from the ViewModelStoreOwner. Here is an example: Let’s create scopes:
scope(qualifier<SomeFragment>())
scope(qualifier<LongLiveScope>()) {
  
viewModel { SomeViewModel ()}
}
Then we link these scopes:
fragmentScope.linkTo(longLiveScope)
Then we inject SomeViewModel into SomeFragment with the
viewModel()
extension, which uses the ViewModelStore from SomeFragment. When SomeFragment is destroyed, its ViewModelStore is also destroyed, and
SomeViewModel::onClear
will be called. However, the SomeViewModel instance will not be destroyed because it is scoped in LongLiveScope, which leads to issues when the same (already cleared) instance of SomeViewModel is reused in new fragments. For example, ViewModel’s coroutines scope will not work because it will be already closed after onCleared. I think the ViewModel should be shared using the shared ViewModelStore, but not using the Koin scope, otherwise, it breaks the lifecycle of the ViewModel itself. I hope I explained this issue in sufficient detail. Can you please explain why the ViewModel definition has changed? And what can I do if the ViewModelStoreOwner is different from the scope, other than rolling back the old ViewModel definition? Thank you!
a

arnaud.giuliani

11/12/2021, 8:17 AM
viewModel in scope can survive to lifecycle changem and then regenerates the instance from current Android ViewModel Factory
as previously it was loosing it completely
referencing ViewModel in cascade this way, is not sometyhing I would advise
View count: 10