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

    Ofir Bar

    12/27/2019, 10:44 PM
    Can someone please explain what is the root cause for this error? I mean, I know that it tells me I am using my ViewModel before onCreate (well, I am actually using it INSIDE onCreate)
    g
    • 2
    • 1
  • o

    Ofir Bar

    12/28/2019, 12:57 PM
    Got it, thank you Victor! @voben I just wonder, what can be an example use case of preferring to instantiate the ViewModel via
    getViewModel()
    over using the lazy instantiation via
    by viewModel
    ?
    v
    • 2
    • 1
  • b

    Ben Abramovitch

    01/02/2020, 5:07 PM
    Is anyone able to take a look at my question from dec 18th? I'm really stuck on what to do, and can't get feedback anywhere? I'm left thinking I'm either doing something wrong, or it's not possible to verify mocks not passed in through the constructor?
    n
    • 2
    • 9
  • g

    g4sarma

    01/08/2020, 1:21 PM
    @arnaud.giuliani would like to get your insight for the same
    Untitled
    a
    • 2
    • 13
  • m

    Manuel Lorenzo

    01/12/2020, 6:57 PM
    I’ve been trying to prepopulate my DB with a RoomDatabase.Callbac() and I see that it is only populated if I fetch the data first (just like it was some sort of lazy way). The problem is that once it’s populated, I don’t get the data back. In theory, it should be prepopulated the first time the DB is initialized, and I’m doing so in a Koin module:
    val databaseModule = module {
        single { HeritageDatabase.getDatabase(get()) }
        single { get<HeritageDatabase>().heritageDao() }
    }
    d
    • 2
    • 1
  • p

    Paolo

    01/16/2020, 3:20 PM
    Hey all, anyone can answer this question: https://stackoverflow.com/questions/59772291/koin-how-to-share-class-instances-between-scopes
    a
    • 2
    • 16
  • m

    Maikals

    01/20/2020, 8:29 AM
    Hi, anyone knows if Koin is compatible with kotlin native? thank you!
    a
    • 2
    • 2
  • s

    Smorg

    01/22/2020, 4:25 AM
    Hi there, I was wondering if it is possible to retrieve a dependency tied to the scope of an activity lifecycle in a fragment (hosted by the activity of course) without using a named scope Say I declare a scope this way:
    val androidModule = module {
    
        scope<MyActivity> {
            scoped { Presenter() }
        }
    }
    and I need to retrieve the
    Presenter
    dependency in a fragment, which API can I use?
    a
    e
    • 3
    • 3
  • b

    Blundell

    01/24/2020, 2:29 PM
    I have two android modules with two koin modules: In Android Module 1)
    private val network1: Module
            get() = module {
                factory<RefreshAuthTokenInterceptor>() bind Interceptor::class
            }
    In Android Module 2)
    private val network2: Module
            get() = module {
                factory<HeadersInterceptor>() bind Interceptor::class
                factory<RetryInterceptor>() bind Interceptor::class
    
                single<InterceptorFactory> {getAll<Interceptor>()}
            }
    App init:
    startKoin {modules(listOf(network1, network2))}
    In terms of gradle: App module depends on Module 1 which depends on Module 2 But the
    getAll<Interceptor>()
    is only returning the 2 instances in the same Koin module. Is this expected behaviour? Is there anyway to get all 3 of the Interceptors?
    d
    • 2
    • 3
  • d

    david.bilik

    01/25/2020, 10:15 AM
    Hi, im having a hard time in finding some info about using koin with
    SavedState
    mechanism. In current documentation there is no mention about that, so i thought that it is not yet release in stable version and I searched for that in alpha
    2.1.0
    where I actually found that for example here https://github.com/InsertKoinIO/koin/blob/2.1.0/koin-projects/koin-androidx-viewmodel/src/main/java/org/koin/androidx/viewmodel/ViewModelFactory.kt but there is nothing in changelog https://github.com/InsertKoinIO/koin/blob/2.1.0/CHANGELOG.md and samples are pretty sparse I think. Is there something im missing? If not, is it something you accept contributions for?
    j
    a
    • 3
    • 7
  • l

    LeoColman

    02/05/2020, 6:23 PM
    I didn't execute with maven tho, I ran with JUnit inside IntelliJ
    e
    • 2
    • 1
  • m

    Mark

    02/06/2020, 7:36 AM
    Suppose I have a suspend function that provides an instance of some interface. How can I use Koin to inject such an instance where required? Like mentioned https://github.com/InsertKoinIO/koin/issues/388
    a
    • 2
    • 5
  • m

    Mark

    02/09/2020, 4:39 AM
    Curious to know if people are passing application
    Context
    in via constructor or just accessing it inline with the help of a top-level property like:
    val appContext by lazy {
        GlobalContext.get().koin.get<Context>()
    }
    Since an application
    Context
    is not mocked (I think!), is there any advantage to passing it into a constructor?
    i
    i
    • 3
    • 5
  • m

    Mark

    02/12/2020, 11:50 AM
    Suppose I have an android library common module with a single koin module specified. Suppose also I would like to run some code (also specified in common module) when that koin module is loaded. Where is the best place to put such code (note: this should not be explicitly called from outside common)?
    a
    • 2
    • 4
  • m

    Mark

    02/15/2020, 9:09 AM
    Can someone explain the rationale behind injection parameters for
    single
    components? Does it mean the parametersOf() is only used the first time the component is fetched/injected? https://doc.insert-koin.io/#/koin-core/injection-parameters
    a
    a
    • 3
    • 3
  • m

    Mark

    02/17/2020, 2:19 PM
    I was reading this article regarding setting up Android Modules with Koin, and noticed that they do loadKoinModules/unloadKoinModules in Activity onCreate/onDestroy. Is this an unusual way to use Koin? I assumed you just set everything up during
    startKoin {}
    and then and loading/unloading would be in rather non-standard scenarios (e.g. when there are large components and so need to free up memory). https://medium.com/better-programming/setting-up-android-modules-with-koin-962534395a3e
    m
    a
    • 3
    • 4
  • k

    kagomez

    02/17/2020, 6:20 PM
    I have something like
    when (deeplink.lastPathSegment) {
        BRANCHES_SEGMENT -> presenter.loadBranches()
        else -> updateHomeState(screenState = HomeScreenState.HomeScreen)
    }
    the presenter is being injected on the Activity and on onStart and onCreate the presenter instance has not been initiliazed yet
    a
    t
    • 3
    • 8
  • a

    Astronaut4449

    02/19/2020, 6:01 PM
    Is there a way to tie a scope to an instance instead of a string identifier (anonymous scope)? Let's assume I have a
    Model
    class, a
    Controller
    class and a
    View
    class. There can be several instances of
    Model
    in the application (scoped), but every one of these models has exactly one
    Controller
    (scoped). Furthermore it shall be possible to have multiple instances of
    View
    pointing to a pair of
    Model
    and
    Controller
    . Afaik you can only tie a scope to a scope-id (string)
    koin.createScope<Model>(scopeId = "I have to provide an id")
    .
    koin.createScope<Model>()
    works, but only once since it is creating a scope-id from the class name. I want a scope to be bound to an instance. Is that somehow possible? I would love to see an API like this:
    val scope1 = koin.createScope<Model>() // idea: scope should be tied to an instance of 'Model' instead of scopeId
    val model1 = scope1.get<Model>() // scoped
    val controller1 = scope1.get<Controller>() // scoped
    val view11 = scope.get<View>() // factory
    val view12 = scope.get<View>()
    
    val scope2 = koin.createScope<Model>() // should create another scope tied to another instance of 'Model'
    val model2 = scope1.get<Model>() // scoped
    val controller2 = scope1.get<Controller>() // scoped
    val view21 = scope.get<View>() // factory
    val view22 = scope.get<View>()
    a
    • 2
    • 15
  • a

    arnaud.giuliani

    02/24/2020, 2:58 PM
    2.1.0
    is stable 🎉
    🎉 20
    :kotlin: 4
    m
    s
    m
    • 4
    • 8
  • a

    aipok

    02/24/2020, 8:15 PM
    I have question for the 2.1.0 release… what is the replacement to
    GlobalContext.get().koin.inject()
    in 2.1.0 for Android? I found
    KoinContextHandler.get()
    or
    getKoin()
    that works the same way, but which is expected to be used as replacement?
    a
    m
    • 3
    • 27
  • e

    Erik

    02/26/2020, 1:31 PM
    I'm also having trouble upgrading to v2.1.0 in my library. My lib is agnostic of the app using it. So my lib doesn't know if we already have a Koin instance, e.g. whether or not the app used
    startKoin {}
    . So basically I want to have a lib-private
    KoinApplication
    /
    Koin
    instance. How do I approach this? It used to work on v2.0.1.
    a
    • 2
    • 78
  • k

    ken

    02/28/2020, 8:57 AM
    Is there difference between Ktor Koin and Core Koin?
    a
    • 2
    • 1
  • m

    Mark

    03/01/2020, 3:54 AM
    When breaking out a fragment+viewmodel into its own library module, what is your go to strategy for handling a click within that fragment that has an impact on other fragments in the application module (shown at the same time in the same activity)? There are many approaches to this. For example, would you use Koin to provide a click listener? Or maybe declare an abstract viewmodel in the library and then subclass it in the app module providing the click listener that way (and then provide the viewmodel to the library through Koin)?
    j
    • 2
    • 4
  • i

    ianbrandt

    03/01/2020, 7:34 PM
    I'm getting a compilation error trying to use the
    declare { }
    DSL from Koin Test documented here: https://doc.insert-koin.io/#/koin-test/testing?id=declaring-a-component-on-the-fly Here are the project sources: https://github.com/sdkotlin/sd-kotlin-talks/blob/16f05dfb7292dcfa87e5df1c5d92b06c66cadba1/di-with-koin/src/it/kotlin/org/sdkotlin/koin/it/hello/HelloModuleIT.kt#L81 I tried
    single
    , and
    factory
    as in the docs, but both result in a:
    Unresolved reference. None of the following candidates is applicable because of receiver type mismatch...
    I thought maybe it could be an issue with the fact that I was using an inline class (experimental) as the component type, but it fails to compile with a simple String type as well:
    declare { single { "testing" } }
    . Am I doing something wrong here, or should I file a GitHub issue? Koin and Koin Test 2.1.1.
    a
    • 2
    • 4
  • a

    aipok

    03/04/2020, 7:42 AM
    It looks like Koin is not compatible with latest 1.3.70 Kotlin version
    :yes: 1
    😩 1
    m
    a
    • 3
    • 2
  • k

    kzotin

    03/05/2020, 9:47 AM
    hi @arnaud.giuliani after update to
    2.1.2
    we're getting
    ERROR: Failed to resolve: org.koin:koin-androidx-scope:2.1.2
    even though this dependency is not used
    a
    • 2
    • 8
  • s

    Saiedmomen

    03/09/2020, 9:03 AM
    is there a replacement API?
    a
    • 2
    • 4
  • a

    arnaud.giuliani

    03/16/2020, 8:47 AM
    Koin 3.x MPP is under preparation to be back in the repo, some good works done by @kpgalligan and share it with us
    🎉 10
    🕺 3
    k
    • 2
    • 1
  • c

    Chills

    03/21/2020, 7:45 AM
    how to start koin , without function? https://pastebin.com/PUHaf1Tu startkoin can't start without function
    a
    • 2
    • 5
  • s

    sunnat629

    03/23/2020, 2:36 PM
    one silly question but informatic, what is the actual difference between
    factory
    and
    single
    in Koin?
    v
    c
    • 3
    • 3
Powered by Linen
Title
s

sunnat629

03/23/2020, 2:36 PM
one silly question but informatic, what is the actual difference between
factory
and
single
in Koin?
v

voben

03/23/2020, 2:38 PM
From the docs
A factory component declaration is a definition that will gives you a new instance each time you ask for this definition
Declaring a singleton component means that Koin container will keep a unique instance of your declared component
https://doc.insert-koin.io/#/koin-core/definitions?id=defining-a-factory
👍 1
c

Chills

03/23/2020, 3:05 PM
both are creational pattern
s

sunnat629

03/27/2020, 3:14 PM
Thank you all
View count: 6