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

    tapchicoma

    03/14/2019, 1:27 PM
    hm, I can't find
    declare { .. }
    in
    2.0.0-beta1
    koin test? Is it removed and what is the replacement?
    • 1
    • 1
  • t

    tapchicoma

    03/14/2019, 2:45 PM
    ok. having following module declaration produces such error:
    data class One(val item: String)
        data class Two(val one: One)
        val testModule = module {
            scope("TEST_SCOPE") {
                scoped { One("zzz") }
                scoped { Two(get()) }
            }
        }
    a
    • 2
    • 28
  • n

    nwh

    03/14/2019, 6:49 PM
    I'm trying to mock a Retrofit setup, specifically the response from the OkHttp client. I have the
    OkHttpClient
    declared as a single dependency, and the Retrofit API as another (which uses
    get()
    for the client). I found a mock setup for OkHttp that uses an interceptor to return a custom response, but I can't figure out how to set it up with koin. How should I do it? When I use
    declareMock
    I start getting errors in OkHttp.. When I copy an identical declaration from the
    declareMock
    to
    single
    in a non-test environment, everything works exactly as expected. It is only when using the
    declareMock
    that there is a problem. Here's the difference in object creation order:
    Mock:
    ----
    Creating client (mock)
    Created client (mock)
    Creating API wrapper
    Creating ProPublica API
    Created ProPublica API
    Created API wrapper
    
    
    Real:
    ----
    Creating API wrapper
    Creating ProPublica API
    Creating client (real)
    Created client (real)
    Created ProPublica API
    Created API wrapper
    a
    • 2
    • 6
  • a

    arnaud.giuliani

    03/15/2019, 8:39 AM
    should be not far from release candidate 👍
    r
    • 2
    • 3
  • k

    kodal

    03/18/2019, 8:11 AM
    @arnaud.giuliani, I can't use koin get<T>() in OkHttp Interceptor, it freezes. Can you help? koin-beta-4, android p
    a
    • 2
    • 1
  • m

    Maikals

    03/18/2019, 4:22 PM
    Thanks! so, if i want to inject a viewmodel in java I have to use the inject method? (The IDE says that the inject method has access private, so I can't use it)
    a
    • 2
    • 2
  • k

    kenkyee

    03/19/2019, 5:52 PM
    General question on Koin in Java...I saw a weird stack overflow when doing something like this: class Something { private OtherClass otherClass = get(OtherClass.class); void someFunction() { otherClass.method(); } } vs. class Something { void someFunction() { get(OtherClass.class).method(); } } Is one preferred over the other? The reason I ask is the first one can cause a stack overflow in Koin depending on how the graph is nested.
    • 1
    • 1
  • k

    kenkyee

    03/19/2019, 5:55 PM
    The second method does the DI lookup more often and in theory should be less efficient though.
    a
    • 2
    • 1
  • k

    kenkyee

    03/19/2019, 7:46 PM
    Also, for Kotlin files, is it wrong to use KoinJavaComponent.get() to get a dependency rather than making the class a KoinComponent just so you can do the Koin Kotlin inject()/get()?
    a
    • 2
    • 1
  • b

    bastienC

    03/20/2019, 4:18 PM
    Hi, got an issue with scopes :
    E/KOIN: [ERROR] - Error while resolving instance for class 'com.x.domain.navigation.Navigator' - error: org.koin.error.NoScopeException: Definition 'Scope [name='Navigator',class='com.x.domain.navigation.Navigator']' has to be used with a scope. Please create and specify a scope to use with your definition
    <- but navigator is scoped, it happend when we try to restart the current activity (with activity.finish() -> startActivity()), any idea ?
    a
    • 2
    • 13
  • j

    Jordan

    03/20/2019, 9:44 PM
    I'm trying to update to 2.0.0-beta-4 from 0.9.1 (i WOULD have followed the migration from 0.9 -> 1.0 guide, but it has been removed from insert-koin.io...)
    • 1
    • 3
  • w

    woodii

    03/27/2019, 8:09 AM
    Hey I really love koin and have 2 questions after upgrading to 2.0. In 1.0 you could use a named qualifier multiple times for different types. Now they can be used only once. Wouldn't it be better to have a name qualifier per type? And second, in koin 1.0 you could log a nice graph when and if dependencies were injected. That doesnt appear in 2.0. Can you enable this somehow?
    a
    • 2
    • 10
  • b

    bdawg.io

    03/27/2019, 7:05 PM
    Are there any guides available to avoid using the GlobalContext?
    a
    • 2
    • 2
  • i

    il_agent

    03/29/2019, 10:47 AM
    Hello ! Could anybody tell what minimal Android api Koin supports ?
    t
    a
    • 3
    • 9
  • t

    tapchicoma

    03/29/2019, 2:01 PM
    mm, I have a question - if I have following module:
    val someModule = module {
       scope(named("some")) {
           scoped { SomeClass(get()) }
       }
    
       single<SomeFunctionTypealias> { { incoming -> get<SomeOtherClass>().process(incoming) } }
    }
    where
    SomeClass
    has
    SomeFunctionTypealias
    as constructor param. Will in this case Koin call
    get<SomeOtherClass>()
    on scope or will it be got from global scope? I suspect a leak in my app because of this
    a
    • 2
    • 6
  • m

    mmaillot

    04/05/2019, 12:49 PM
    Hello, I have an android fragment with a viewModel. I use private
    by sharedViewModel()
    to inject the view model. But I want to create my ViewModel with an argument provided via intent in the activity. Is it possible ?
    • 1
    • 1
  • d

    Denys

    04/08/2019, 6:31 PM
    Hello! How to provide dependencies in modules which depend on the entities that are dynamically initialized in view, f.e. callbacks
    a
    • 2
    • 1
  • a

    arnaud.giuliani

    04/09/2019, 7:50 AM
    could be a new feature, but for now the better way is to handle it with try catch
    n
    • 2
    • 5
  • n

    nwh

    04/09/2019, 5:58 PM
    When should I do
    val obj: Type = get()
    versus
    val obj: Type by inject()
    Is it just a decision based on if I want it to be lazy or not? I'm not sure what to consider there.
    b
    • 2
    • 1
  • s

    sahil Lone

    04/10/2019, 11:03 AM
    Hello guys, can anyone help me here
    module {
               single { appConfig } ,
               single { (appConfig: AppConfig) ->
                    appConfig.dbConfig
                }
                single { (dbConfig: DbConfig) ->
                    val config = HikariConfig()
                    config.jdbcUrl = "${dbConfig.jdbcUrl}/${dbConfig.database}"
                    config.username = dbConfig.username
                    config.password = dbConfig.password
                    HikariDataSource(config)
                } bind DataSource::class
    
                single { (dataSource: DataSource) ->
                    Database.connect(dataSource)
                }
            }
    Exception in thread "main" org.koin.core.error.InstanceCreationException: Could not create instance for [type:Single,class:'com.zaxxer.hikari.HikariDataSource', classes:javax.sql.DataSource] Caused by: org.koin.core.error.NoParameterFoundException: Can't get parameter value #0 from org.koin.core.parameter.DefinitionParameters@4fe01803
    t
    • 2
    • 3
  • n

    nwh

    04/11/2019, 6:12 PM
    How bad of an idea is this? Performance aside
    inline fun <T> withKoin(crossinline block: KoinComponent.() -> T): T {
    	return object : KoinComponent { val v = block() }.v
    }
    b
    • 2
    • 1
  • s

    sanogueralorenzo

    04/20/2019, 4:27 AM
    Hello! Trying out 2.0.0-rc-3 now and found that
    name = "x"
    is no longer used and it is asking for a qualifier (+ I can see a named function in autocomplete). How should it be now? Also, what is the advantage of this? To not require strings for names like List<String> and put that as a type of the Qualifier? Thanks!
    b
    • 2
    • 1
  • t

    Tmpod

    04/26/2019, 7:39 PM
    Hey! How do the
    fileProperties
    work in Koin? I can't seem to make the framework find the file...
    d
    • 2
    • 5
  • t

    Tmpod

    04/26/2019, 7:39 PM
    the docs are a bit vague on it
    a
    • 2
    • 1
  • q

    quver

    05/03/2019, 5:22 PM
    Hello guys could you please tell me is there list of what big companies use Koin in production? (It's important for our PM)
    b
    a
    • 3
    • 3
  • a

    arnaud.giuliani

    05/06/2019, 8:48 AM
    https://github.com/InsertKoinIO/koin/issues/440
    m
    • 2
    • 3
  • a

    arnaud.giuliani

    05/06/2019, 10:03 AM
    2.0.0 stable release soon 🎉 👍
    🎉 11
    :yes: 3
    😍 12
    q
    • 2
    • 1
  • b

    bastienC

    05/09/2019, 9:53 AM
    single {
            DeviceController(
                InternetManager(androidContext()) as InternetDataSource,
                DeviceInformation(androidContext()) as DeviceInformationDataSource
            )
        } bind Device.Connection::class bind Device::class
    was working before on 2.0.0-rc1, seems not working anymore on 2.0.0-GA, any idea ?
    • 1
    • 1
  • a

    arnaud.giuliani

    05/09/2019, 10:28 AM
    you may use
    getKoin().bind<DeviceController,Connection>
    instead @bastienC
    b
    • 2
    • 6
  • a

    arnaud.giuliani

    05/10/2019, 6:07 AM
    To sum up:
    module {
        single { Simple.Component1() } bind Simple.ComponentInterface1::class
        single { Simple.Component2() } bind Simple.ComponentInterface1::class
        single { Simple.UserComponent(bind<Simple.Component1, Simple.ComponentInterface1>()) }
    }
    - you can get directly the instances with
    get<Simple.Component1>()
    ,
    get<Simple.Component2>()
    -
    get<Simple.ComponentInterface1>()
    will throw an error and tell you to use
    bind
    because can’t choose between the 2 definitions - you can use
    bind<>()
    to resolve a component in the DSL -
    getAll<Simple.ComponentInterface1>()
    give us the 2 instances
    s
    k
    • 3
    • 10
Powered by Linen
Title
a

arnaud.giuliani

05/10/2019, 6:07 AM
To sum up:
module {
    single { Simple.Component1() } bind Simple.ComponentInterface1::class
    single { Simple.Component2() } bind Simple.ComponentInterface1::class
    single { Simple.UserComponent(bind<Simple.Component1, Simple.ComponentInterface1>()) }
}
- you can get directly the instances with
get<Simple.Component1>()
,
get<Simple.Component2>()
-
get<Simple.ComponentInterface1>()
will throw an error and tell you to use
bind
because can’t choose between the 2 definitions - you can use
bind<>()
to resolve a component in the DSL -
getAll<Simple.ComponentInterface1>()
give us the 2 instances
s

sloydev

05/10/2019, 6:50 AM
So you can
val instance: Simple.ComponentInterface1 = bind<Simple.Component1, Simple.ComponentInterface1>()
, is that right?
a

arnaud.giuliani

05/10/2019, 7:13 AM
yes
s

sloydev

05/10/2019, 7:14 AM
Cool, wasn't sure if I got it right
Then is there any difference between that and
val instance: Simple.ComponentInterface1 = get<Simple.Component1>()
? Or just different API?
a

arnaud.giuliani

05/10/2019, 8:10 AM
in that case will be the same
k

kenkyee

05/10/2019, 2:03 PM
Sounds good..not sure you need getAll() but doesn't hurt
a

arnaud.giuliani

05/10/2019, 2:09 PM
getAll can be interesting to scan definitions tagged with the same type
if you have several definition of
Feature
or
Plugin
for example
can help to write dynamic behaviour
k

kenkyee

05/10/2019, 2:20 PM
good point 🙂
View count: 4