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
  • c

    carloxavier

    07/21/2022, 11:48 AM
    ok what I found is the koin-test is a transitive dependency wich supports multiplatform, via org.jetbrains.kotlin.multiplatform plugin this koin-test uses the kotlin block to declare the jvm target, and this seems by default at language level 11. This forces us to upgrade to AGP 7, because data binding on AGP 4.2 doesn't seem to be compatible with java 11.
  • j

    Jonathan Willis

    07/22/2022, 5:48 PM
    anyone else have trouble setting up junit5 koin tests?
  • j

    Jonathan Willis

    07/22/2022, 5:48 PM
    I’m getting this error:
    |- No definition found for class:'io.vertx.rxjava3.core.Vertx'. Check your definitions!
    org.koin.core.error.NoBeanDefFoundException: |- No definition found for class:'io.vertx.rxjava3.core.Vertx'. Check your definitions!
  • j

    Jonathan Willis

    07/22/2022, 5:49 PM
    even though i’m creating the modules as shown in the documentation:
    @JvmField
      @RegisterExtension
      val koinTestExtension = KoinTestExtension.create {
          modules(
            module {
              single {
                println("creating vertx instance")
                Vertx.vertx()
                println("done creating vertx intstance")
              }
            ...
       }
    l
    • 2
    • 3
  • j

    Jonathan Willis

    07/22/2022, 5:55 PM
    is there a way to add to an existing koin module in a test or @beforeEach method ?
    • 1
    • 2
  • y

    Yasutaka Kawamoto

    07/24/2022, 5:16 AM
    Is there any workaround for the issue? https://github.com/InsertKoinIO/koin/issues/1364
  • j

    Joe Altidore

    07/25/2022, 10:14 AM
    Hello devs, I am trying to install "Koin" for DI. I have added the Koin dependency to my gradle but it doesn't seem to install.
    implementation("io.insert-koin:koin-core:3.2")
    
    implementation("io.insert-koin:koin-ktor:3.2")
    This block is having an error
    install(Koin) {
    /*logic here**/ } Unresolved reference: Koin
    e
    • 2
    • 2
  • j

    Jakub Gwóźdź

    07/29/2022, 7:08 AM
    Hi there. So I have very basic setup with a few modules and some
    single { … }
    in them. Can I somehow ensure that if these singletons implement AutoCloseable, their `.close()`s will be called at
    stopKoin()
    ?
    • 1
    • 1
  • s

    Stylianos Gakis

    07/30/2022, 7:48 PM
    I got an extra koin module in a separate gradle module which binds some extra implementations of an Interface like
    single<MyInterfaceImpl1> { MyInterfaceImpl1() } bind MyInterface::class
    I load that module using
    loadKoinModules
    which acts as a functions that populates the global koin registry. Then on another koin module I’m doing
    single<SendHAnalyticsEventUseCase> {
      val allInterf = getAll<MyInterface>().distinct()
      Foo(allInterf)
    }
    However I figured that I am not getting those other interfaces on my getAll() and I am guessing this has to do with the order of how this is executed, as after I’ve added some Log.d in there it does fetch my other impls too 🤯 Is there a way to make this order more reliable or some approach where I can avoid this altogether? 🤔
  • j

    janvladimirmostert

    07/30/2022, 8:07 PM
    Out of curiosity, when I call
    single { Repository(get(named("remote")),get(named("local")))
    where is that Repository instance actually stored? and when I call
    val repo : Reposity by inject
    where is that instance being pulled from again? is there any interesting magic happening here or is it literally keeping that instance in something like a hashmap?
    s
    • 2
    • 2
  • z

    Zach

    08/02/2022, 3:59 PM
    Forgot to add my application class to the manifest, whoopsies! I started a brand new compose project and am setting up a simple viewmodel and Koin injection. I have startKoin set up in my application class with the modules containing the viewmodels, but when I run the application it hits the line to inject the viewmodel into a composable and crashes with
    KoinApplication has not been started
    . I followed the process for compose viewmodels in the documentation. Am I missing something?
    Koin version: 3.2.0 Compose 1.2.0
  • a

    Austin Pederson

    08/02/2022, 6:13 PM
    Hey can anyone that uses Koin in a KMM project let me know how I can instantiate a dependency in iOS code and then add it to the dependency graph of Koin?
    • 1
    • 1
  • s

    Shervin

    08/03/2022, 3:11 PM
    Hey everyone! I have a quick question about
    3.2.0
    Is the stable version officially out? I can not see the release tag in github.
    a
    • 2
    • 2
  • p

    Pedro Francisco de Sousa Neto

    08/05/2022, 6:23 PM
    Hello everyone! I’ve a doubt not totally connected to the Koin usage, but maybe you can help me. Is it possible to split errors caused by
    org.koin.core.scope.Scope.throwDefinitionNotFound
    in Firebase Crashlytics? I always need to navigate by crash events page to check each stacktrace to identify if it’s a new broken code or existing one.
    a
    • 2
    • 3
  • v

    Vasyl Dizhak

    08/07/2022, 8:50 AM
    Hey folks, I’m getting started with koin and ktor and have some difficulties with the initial setup as I practically can’t make it working with tests to inject different implementation there.
    fun Application.webModule(koinModules: List<org.koin.core.module.Module> = listOf(applicationModule)) {
    
        install(Koin) {
            printLogger(level = <http://Level.INFO|Level.INFO>)
            modules(koinModules)
        }
        val tracksController: TracksControllerInterface by inject()
    
        configureRouting(tracksController)
    }
    In the tests I create the mock that I inject
    private val tracksController = mockk<TracksController>()
    
        private val testModule = module {
            single<TracksControllerInterface> { tracksController }
        }
    
        @Test
        fun `GET tracks returns list of available tracks`() = testApplication {
            application {
                stopKoin()
                webModule(koinModules = listOf(testModule))
            }
    But I keep getting issue that Koin plugin was already installed
    • 1
    • 1
  • b

    bharath

    08/10/2022, 6:37 AM
    Hey guys, i have added
    viewModel { MainViewModel() }
    in koin module and injecting the view model with
    val mainViewModel: MainViewModel by viewModel()
    val mainViewModel2 = getViewModel<MainViewModel>()
    these both ways and setting value in one composable, and injected the same viewmodel in similar way in other composable, but instead of returning the existing instance it always returns new instance of that view model in the composable, can anyone help me with this?
    c
    • 2
    • 9
  • b

    bharath

    08/10/2022, 6:39 AM
    in documentation i can see we can specify owner and scope, but not sure where exactly we should add it You can specify the
    owner
    & `scope`: inline fun <_reified_ T : ViewModel> getViewModel( qualifier: Qualifier? = null, owner: ViewModelOwner = getComposeViewModelOwner(), scope: Scope = GlobalContext.get().scopeRegistry.rootScope, noinline parameters: ParametersDefinition? = null, ) Where ViewModelOwner can be used to pass a StoreOwner (like navigation): @Composable fun getComposeViewModelOwner(): ViewModelOwner { return ViewModelOwner.from( LocalViewModelStoreOwner.current!!, LocalSavedStateRegistryOwner.current ) }
  • b

    bharath

    08/10/2022, 6:39 AM
    and on adding this will resolve the issue?
  • l

    Lukasz Kalnik

    08/12/2022, 12:42 PM
    I would be also interested in sharing the same ViewModel instance between a composable (or multiple composables) and host Fragment/Activity. My use case is that I have click callbacks in the composables which trigger events in the viewmodel. Then host Fragment subscribes to this event to show snackbar or trigger navigation.
    m
    • 2
    • 26
  • b

    benkuly

    08/31/2022, 6:43 AM
    Does anyone run koin on JS? My code works on JVM and Native. I get the following exception:
    j
    • 2
    • 2
  • l

    Lukasz Kalnik

    09/02/2022, 12:08 PM
    How can I inject the same CoroutineScope in two classes, e.g. a ViewModel and a Repository? Is it enough to just create a named CoroutineScope instance and inject it in both?
    a
    j
    • 3
    • 25
  • r

    Robert Jaros

    09/04/2022, 1:05 PM
    Hello, does
    koin-ktor
    works with Ktor server native target?
  • r

    Robert Jaros

    09/11/2022, 5:56 AM
    Is there an equivalent of a Guice child injector in Koin?
    a
    • 2
    • 3
  • m

    Marcin Wisniowski

    09/12/2022, 6:49 PM
    I don't know if it's just me, but every time I enter the Koin website when starting a new project, I have no clue if I should click the GET STARTED or SETUP button. They both mean the same thing.
    a
    p
    • 3
    • 8
  • c

    camiloparradev

    09/16/2022, 10:33 PM
    Hello, I want to provide a different instance of a ViewModel into many Composables.
    // Module
    viewModel { MyViewModel() }
    class MyViewModel : ViewModel() { 
       var feedId: Int by Delegates.notNull()
    }
    @Composable
    fun MyComposable(myViewModel: MyViewModel = getViewModel(), feedId: Int) { // Using myViewModel with a specific feedId }
    feeds.forEach {
        MyComposable(feedId = it.feedId)
    }
    So each
    MyComposable
    can have its own viewModel, but what seems to happen to me is that all
    MyComposable
    are sharing the same instance of
    MyViewModel
    . Like
    getViewModel()
    is always providing the same instance. Am I right? Is there a way to provide different instances for each
    MyComposable
    ?
    m
    • 2
    • 1
  • m

    mbonnin

    09/19/2022, 1:59 PM
    Is there a specific reason Koin now requires
    "org.gradle.jvm.version": 11
    ?
    a
    • 2
    • 35
  • j

    Javier

    09/20/2022, 8:37 AM
    Koin androidx compose 3.2.1 is missing or they are not sharing the same version?
    a
    j
    • 3
    • 9
  • c

    clark

    09/20/2022, 5:40 PM
    I noticed today that the
    GlobalContext
    (at least on the JVM) is a top level object. Does this have any implications on process death on Android? Do you need to restart Koin after process death? If not, how does it work?
    a
    • 2
    • 2
  • j

    jmfayard

    09/22/2022, 7:52 AM
    Bonjour I think that Koin introduces a caching problem with Gradle in my project. In
    src/main
    I register things in Koin with the syntax
    singleOf(::RegisterUser)
    When I run tests I have errors like
    'NoSuchMethodError void xxx.RegisterUser.<init>(xxx.FirstClass, xxx.SecondClass)'
    The error goes away if I add a blank line somewhere in
    src/main
    therefore invalidating the cache. Does that sounds familiar?
    a
    • 2
    • 14
  • a

    aridder

    09/22/2022, 1:28 PM
    How can I use 3.2.1 with this fix in my app? https://github.com/InsertKoinIO/koin/issues/1350
    j
    • 2
    • 6
Powered by Linen
Title
a

aridder

09/22/2022, 1:28 PM
How can I use 3.2.1 with this fix in my app? https://github.com/InsertKoinIO/koin/issues/1350
Failed to resolve: io.insert-koin:koin-androidx-compose:3.2.1
With io.insert-koin:koin-androidx-compose:3.2.0"
org.koin.core.error.DefinitionParameterException: No value found for type 'androidx.lifecycle.SavedStateHandle'
val appModule = module {

    single { OfflineWorkerUtil }
    single { OfflineWorkerUtil.zTRANSPORT_VIS_SRV_Entities }
    single { DeliveryRepository(zTRANSPORT_VIS_SRV_Entities = get()) }
    single { TransportRepository(zTRANSPORT_VIS_SRV_Entities = get()) }
    viewModel { DeliveryViewModel(savedStateHandle = it.get(), deliveryRepository = get()) }
    viewModel { params -> DeliveriesViewModel(savedStateHandle = params.get(), deliveryRepository = get()) }
    viewModel { ScannerViewModel(savedStateHandle = it.get(), deliveryRepository = get()) }
    viewModel { SettingsViewModel() }
    viewModel { TransportViewModel(transportRepository = get()) }
}
composable(Screen.Transport.route) { navbackStackEntry ->
    DeliveriesScreen(
        deliveriesViewModel = getViewModel(),
        navigateBack = { navController.navigateUp() },
        navigateToDelivery = { transportId, deliveryNumber ->
            navController.navigate(
                Screen.Delivery.createRoute(
                    transportId,
                    deliveryNumber
                )
            )
        }
    )
}
j

John O'Reilly

09/22/2022, 1:31 PM
https://kotlinlang.slack.com/archives/C67HDJZ2N/p1663663021354469
a

aridder

09/22/2022, 1:32 PM
Thank you!
View count: 7