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

    Marko Kunic

    11/15/2021, 2:56 PM
    Hello, I am wondering can you define a koin module in a 3rd party library, and then just import that into your koin application? (eg. we have a library that we want to maintain its own wiring with koin as we use koin in our main application)
    a
    • 2
    • 3
  • a

    arnaud.giuliani

    11/22/2021, 5:58 PM
    The question is, what do you prefer? • add magically Activity/Fragment inside the
    inject
    • have a dedicated API for that:
    injectActivity
    or something else
    w
    e
    k
    • 4
    • 5
  • h

    holgerbrandl

    11/22/2021, 9:06 PM
    Just FYI, to provide some thankful feedback 🙂: Thanks to the great docs regarding context isolation, I managed to implement a global dependency context using thread-local. By doing, so the kalasim-user can run multiple simulations at ease in parallel with isolated dependency contexts without even thinking about dependencies. And whenever a simulation is started it makes sure to set the correct koin context for the current thread. See https://github.com/holgerbrandl/kalasim/blob/master/src/main/kotlin/org/kalasim/misc/DependencyContext.kt and as example https://www.kalasim.org/examples/atm_queue/#parallel-whatif
    a
    • 2
    • 1
  • l

    Lilly

    11/24/2021, 7:22 PM
    Can someone tell me why by
    inject
    will always try to use
    inject
    from `org.koin.java.KoinJavaComponent.inject`:
    val parser: LegacyParser by inject() // Error: No value passed for parameter 'clazz'
    I'm using it in a test class of an android project. I have implemented io.insert-koin:koin-core io.insert-koin:koin-android
    m
    a
    • 3
    • 3
  • a

    arnaud.giuliani

    11/26/2021, 4:35 PM
    do you have some stacktrace errors?
    e
    j
    • 3
    • 2
  • m

    Marko Kunic

    11/29/2021, 10:41 AM
    gonna reshare in case I missed something, but I am unable to find anything that would do this, meaning I have to register all DI "services" even if they only have
    get()
    ?
    c
    a
    c
    • 4
    • 8
  • l

    Lilly

    12/05/2021, 2:09 AM
    How can I mock
    androidContext
    with `KoTest`/ using `checkKoinModules`:
    internal class DependencyGraphTest : KoinTest, WordSpec() {
        init {
            "Koin" should {
                "inject my components" {
                    checkKoinModules(moduleGroupA + moduleGroupB + module {
                        // mock android context ??
                    })
                }
            }
        }
    }
    • 1
    • 1
  • l

    Lilly

    12/05/2021, 2:16 AM
    In 3.1.3
    checkKoinModules
    was introduced and on github it refers to the checkModules page but there is still the "deprecated" approach explained
    [ADDED]
     
    [test]
     - Introduce new 
    checkKoinModules
     and DSL to help verify modules - https://insert-koin.io/docs/reference/koin-test/checkmodules
    [DEPRECATED]
     
    [test]
     - deprecate old 
    checkModules
     function, in favor of new API 
    checkKoinModules
    a
    • 2
    • 1
  • e

    Emirhan Emmez

    12/08/2021, 8:52 AM
    Is Koin supporting Ktor 1.6.6? Because when i upgrade from 1.6.5 to 1.6.6. This error occurs: Exception in thread "main" java.lang.NoSuchMethodError: 'double kotlin.time.Duration.toDouble-impl(long, java.util.concurrent.TimeUnit)' This error also occurs when i upgrade kotlin version from 1.5.x to 1.6.0 I opened an issue about this. https://github.com/InsertKoinIO/koin/issues/1243
    j
    • 2
    • 1
  • a

    Aaron Pradhan

    12/10/2021, 7:24 PM
    Anyone know how to share a ViewModel between a parent fragment and child fragments (specifically in a ViewPager2) using delegated properties with Koin? I am only familiar with 
    by sharedViewModel()
     (which is shared with the parent activity, not parent fragment) and 
    by viewModel()
     (which I believe creates a new ViewModel instance for the child class). I'm using 
    by viewModels({ requireParentFragment() })
     right now, which works fine, but it's not using Koin. I looked at this article, which suggested 
    by viewModel(owner = { ViewModelOwner.Companion.from(requireParentFragment().viewModelStore) })
    , but that doesn't work anymore. Similarly, this article suggested 
    by sharedViewModel(from = { requireParentFragment() })
    , but the 
    from
     keyword doesn't exist anymore.
    m
    • 2
    • 2
  • r

    Ruben Quadros

    12/11/2021, 3:35 PM
    Hi guys, can I use
    fileProperties
    in a KMM project? I have separate android and ios modules and I am not able to access it in ios module. Using koin version
    3.1.4
    a
    • 2
    • 1
  • x

    xxfast

    12/14/2021, 12:30 PM
    With koin-compose 3.1.4, i’ve noticed that
    getStateViewModel
    is
    @Deprecated
    . How would one inject a view model in a
    @Composable
    with a
    SavedStateHandle
    passed through the params?
    a
    • 2
    • 3
  • p

    Patrick Ramsey

    12/14/2021, 6:25 PM
    I’ve noticed that koin-test 3.1.4 depends specifically on kotlin-test-* 1.5.31. Is there any timeline for supporting kotlin-test 1.5.32?
    • 1
    • 1
  • s

    Scott Kruse

    12/15/2021, 9:13 PM
    Whats a good way to inject koin dependencies in top level functions?
    a
    • 2
    • 1
  • m

    Marko Kunic

    12/16/2021, 4:50 PM
    is there a way to override koin dependencies in tests? (eg. I don't want http client making request to 3rd party in tests)
    a
    • 2
    • 13
  • x

    xxfast

    12/21/2021, 10:13 AM
    Hi all, trying to use koin on the native side, and i’m running into this
    Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)
    with very little output from the console as to why. Its pointing to this
    App`kfun:org.koin.core.module.Module#<get-mappings>(){}kotlin.collections.HashMap<kotlin.String,org.koin.core.instance.InstanceFactory<*>>:
    Has anyone encountered this before?
    • 1
    • 2
  • c

    coroutinedispatcher

    12/26/2021, 10:28 AM
    Hi 👋 Is there any current issue with koin or maven? I am trying to import it in a ktor project but it always fails to sync:
    Could not resolve io.insert-koin:koin-ktor:"2.2.3".
    My setup:
    repositories {
        mavenCentral()
        maven { url = uri("<https://maven.pkg.jetbrains.space/public/p/ktor/eap>") }
    }
    Then dependencies:
    dependencies {
        ...
        implementation ("io.insert-koin:koin-ktor:$koin_version")
    }
    And in
    gradle.properties
    koin_version= "2.2.3"
    Also added in the same file, maybe this is the mistake:
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("io.insert-koin:koin-gradle-plugin:2.2.3")
        }
    }
    j
    • 2
    • 2
  • r

    Ruben Quadros

    12/26/2021, 1:55 PM
    Hi, what is the equivalent of
    hiltViewModel()
    in koin? I want to get parameters passed to compose navigation using
    SavedStateHandle
    in my viewmodel.
    x
    a
    • 3
    • 33
  • v

    Vivek Modi

    01/01/2022, 5:25 PM
    Hey I am new in Koin. What are d/w koin v2 and v3?
    a
    • 2
    • 2
  • b

    Brian Donovan

    01/03/2022, 7:18 PM
    how do I do a constructor injection with Koin?
    a
    • 2
    • 1
  • b

    Brian Donovan

    01/03/2022, 7:19 PM
    r
    • 2
    • 6
  • m

    Malachi de Ælfweald

    01/07/2022, 3:05 PM
    I see release notes and a tag for v 3.1.5; but it doesn't appear to have posted to Maven Central. Was that intentional?
    a
    • 2
    • 8
  • a

    Aidan Low

    01/18/2022, 6:33 PM
    We’re researching unifying portions of our Android and iOS apps by moving core logic into a KMM library, very early stages of research. Is it possible to use Koin to inject classes from that KMM library into the Android/iOS classes, or would I need to export simple constructors from the KMM module and then define the DI graph inside the Android and iOS applications? (or is this even possible on iOS?)
    j
    • 2
    • 7
  • a

    aipok

    01/23/2022, 11:56 AM
    What is the expected way to override declarations in unit tests for specific definitions? I have class
    FaceProcessor
    that has param from MLKit and I want to override this
    MlKit
    dependency in unit tests with a mock implementation. What is the best way to do this?
    e
    • 2
    • 1
  • m

    Matthew Laser

    01/27/2022, 10:19 PM
    is it possible to easily inject a viewmodel into a Service? In trying to inject this via
    by viewModel()
    per the docs, I wind up with the following:
    java.lang.ClassCastException: com.myapp.MyService cannot be cast to androidx.lifecycle.ViewModelStoreOwner
    Doing
    by viewModel()
    inside of
    Activity
    and
    ComponentActivivty
    works fine. I also tried switching from
    Service
    to
    LifecycleService
    with no luck. Any help is appreciated! 🙂
    w
    • 2
    • 7
  • j

    Jacob Hughes

    02/01/2022, 11:32 AM
    Seeing an inconsistent issue with initialising Koin when running iosX64 tests on a multiplatform project. I see get the following error when I run the entire suite of tests
    kotlin.IllegalStateException: KoinApplication has not been started
    . When I run the test individual the test passes as expected. For context each of my test classes extends implements this abstract class:
    abstract class KoinTest : KoinComponent {
    
        @BeforeTest
        fun beforeTest() {
            println("Starting Koin")
            startKoin {
                printLogger(Level.ERROR)
                modules(
                    module {
                        single { Log(testing = useMocks) }
                    },
                )
            }
        }
    
        @AfterTest
        fun after() {
            stopKoin()
        }
    }
    From my build.gradle
    dependencies {
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
            classpath("com.android.tools.build:gradle:7.0.4")
    }
    val commonTest by getting {
                dependencies {
                    implementation(kotlin("test"))
                    implementation(kotlin("test-common"))
                    implementation(kotlin("test-annotations-common"))
                    implementation("io.kotest:kotest-assertions-core:5.0.1")
                    implementation("io.kotest:kotest-framework-engine:5.0.1")
                    implementation("app.cash.turbine:turbine:0.7.0")
                    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
                    implementation("io.insert-koin:koin-core:3.1.5")
                }
            }
    Has anyone come across any similar issues?
    a
    • 2
    • 2
  • b

    bloder

    02/07/2022, 2:04 AM
    Hey! Once FIR is released, is it planned to bring a compiler extension to create a compile time dependency resolution to Koin? I see as a good approach combine Koin DSL with compile time benefits but I don't know if is considered by community. (Also I have plans to build one, then just to know if will be officially considered)
    a
    • 2
    • 5
  • m

    miqbaldc

    02/07/2022, 3:01 AM
    Does it possible to lock the Koin modules and dependency in some sort of
    :koin-bridge
    module as well? Related: https://link.medium.com/YNApqhYurnb To avoid leaking API of such data layer in the application layer. So the modules provider exist in the
    :koin-bridge
    , the
    koin-bridge
    will depend on domain, & data (for concrete implementation of domain repository) And our application/presentation layer will depends on
    koin-bridge
    instead of depends directly
    :data
    layer
    a
    • 2
    • 7
  • t

    tim

    02/08/2022, 2:27 PM
    I need to access a singleton from an inline function … any suggestions? eg how do I access a
    single { something}
    value outside of a KoinComponent?
    a
    • 2
    • 2
  • p

    Peter Hsu

    02/12/2022, 9:45 PM
    Multiplatform/Native/Koin question: I'm not sure what the "correct" way is to utilize Koin when I need to provide an implementation in iOS in swift. There are some 3rd party libs that are in swift that I would like to inject into the Koin modules, which are all defined in the common shared code.
    • 1
    • 1
Powered by Linen
Title
p

Peter Hsu

02/12/2022, 9:45 PM
Multiplatform/Native/Koin question: I'm not sure what the "correct" way is to utilize Koin when I need to provide an implementation in iOS in swift. There are some 3rd party libs that are in swift that I would like to inject into the Koin modules, which are all defined in the common shared code.
e.g., I have an interface
CommonIF.kt
defined in commonMain/interfaces, and a
CommonImpl.kt
in androidMain. In iOS, this is implemented in swift by implementing the
CommonIF
interface. Now the question is how I can make this available to Koin when calling
startKoin
on in my iosMain code. I have an
ModuleLoader
that starts koin and loads the module. The naive approach that I've been using for testing is to add a constructor parameter to
ModuleLoader(val commonImpl: CommonIF)
and provide that in the module by returning this item:
single<CommonIF> { commonImpl }
This breaks the purpose of DI and makes the interface fairly messy and also requires eager loading of these native implementations. Is there a way to clean this up so that the iOS instance is lazily loaded? Is there a way to define Koin modules in swift so that I could just pass in iOS specific Koin modules to the
ModuleLoader
?
View count: 14