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

    yazazzello

    05/13/2019, 1:14 PM
    Hi. First of all thanks for Koin. great tool. Have a question: I’ve been busy with migrating to 2.0 - everything is good, but how do I mock/override definitions in scopes? (for testing) Thanks
    a
    • 2
    • 6
  • p

    Piotr Prus

    05/16/2019, 6:04 AM
    Hello everyone, I am using Koin to inject shared preferences instance. I have one instance which works fine, but now i would like to add the second. How can I distinguish which one should be used? Here is my implementation:
    val preferencesModule = module {
        single { provideSettingsPreferences(androidApplication()) }
    }
    
    private const val PREFERENCES_FILE_KEY = "com.myapp.shared_preferences"
    
    private fun provideSettingsPreferences(app: Application): SharedPreferences =
            app.getSharedPreferences(PREFERENCES_FILE_KEY, Context.MODE_PRIVATE)
    p
    a
    • 3
    • 4
  • b

    Benoit Duffez

    05/16/2019, 10:36 AM
    I think I'll go with zero arg constructor and
    by inject
    at the top of the class, looks nicer anyway
    a
    • 2
    • 1
  • d

    Davide Giuseppe Farella

    05/19/2019, 5:35 PM
    I’m wondering which is the best way for handle a multi-module app with koin. Actually I got an Android project and a structure like this (
    ->
    = depends by ):
    app -> feature modules 
    &
    app -> "DImodules" module
    &
    DImodules -> all other modules ( feature and business )
    In this way app takes a reference to all the koin modules from DImodules, without directly depend by them, but I don’t think this is an awesome solution. Also I would like to invert the dependencies and let feature modules depends by app, but in this way I would have a dependency circle
    features -> app -> DImodules -> features
    . Removing DImodules I wouldn’t know how to initialize other modules 🙄
    👍 1
    a
    s
    • 3
    • 9
  • a

    arnaud.giuliani

    05/27/2019, 4:10 PM
    Koin 2.0 is out: https://medium.com/koin-developers/ready-for-koin-2-0-2722ab59cac3
    🕺 8
    ♥️ 1
    🎉 27
    👛 1
    ❤️ 1
    c
    • 2
    • 2
  • c

    chavi

    05/28/2019, 11:15 AM
    in koin 2.0 how can we use
    org.koin.android.ext.android.setProperty
    ??
    a
    • 2
    • 2
  • p

    Paulius Ruminas

    05/29/2019, 2:03 PM
    Hello, I just started using koin in ktor project and I added additional functionality to allow registration of singleton by KClass argument e.g.:
    // Register by KClass
    private fun Module.single(
        type: KClass<*>,
        createdAtStart: Boolean = false,
        override: Boolean = false
    ): BeanDefinition<*> {
        val beanDefinition = BeanDefinition<Any>(
            qualifier = null,
            scopeName = null,
            primaryType = type
        ).apply {
            this.definition = {
                val constructor = type.getFirstJavaConstructor()
                val args = getArguments(constructor, this)
    
                constructor.makeInstance(args)
            }
            this.kind = Kind.Single
        }
    
        declareDefinition(beanDefinition, Options(createdAtStart, override))
    
        return beanDefinition
    }
    
    // Inject by KClass
    private fun <T : Any> Application.inject(type: KClass<T>): Lazy<T> = lazy { getKoin().rootScope.get(type.java) }
    
    // Module declaration
    val myModule = module {
        // findKClasses - returns List<KClass<*>>
        findKClasses().forEach { single(it) }
    }
    We have classes that we need to resolve dynamically by KClass so that is why we need an ability to register them by KClass. It works now but I wonder how much this code is prone to breaking changes in the future. Or is there an "official way" to achieve this?
    a
    • 2
    • 6
  • r

    rg

    06/03/2019, 9:45 AM
    guys, I have some doubts about how longer lives a single instance and the result of a factory instances. I already understand that single=bean=a lazy instance that can be reused anytime that it’s needed, and factory is a factory of these beans = singles. My main doubt is, if I have a factory of usecases/interactors, how long will live usecase1, usecase2 etc? Is this always engaged with application scope? Or should I define a new scope to make my usecase lives until viewmodel.onCleared(e.g)?
    a
    • 2
    • 14
  • k

    kenkyee

    06/07/2019, 9:32 AM
    In the past, we could use a string name.... This doesn't seem to work any more because the lookups in the last life cycle scope seems to use the activity name always...
    a
    • 2
    • 2
  • d

    david.bilik

    06/09/2019, 6:03 PM
    What is the best practice in handling koin modules in multimodule project? I ‘ve come up with solution that each module will provide list od modules that he wants to load to the whole graph and in the top level App module I will gather all of these and put them inside loadKoinModules function but maybe there is something better?
    s
    • 2
    • 5
  • a

    arnaud.giuliani

    06/11/2019, 4:02 PM
    is your gradle config file ok?
    l
    • 2
    • 2
  • a

    arnaud.giuliani

    06/13/2019, 3:59 PM
    in
    getViewModel
    you can pass a KClass & the name is considered as the key
    d
    • 2
    • 6
  • o

    Ove Stoerholt

    06/17/2019, 11:25 AM
    Hi! I have a bunch of fragments, each with their own viewmodel, that will act as a ‘wizard’/‘workflow’ with multiple states. I have used the Tinder StateMachine library for state implementation. Could someone please point me in the right direction for state sharing between fragments/viewmodels? I figure I have to write a KOIN shared viewmodel, but I am not sure I have understood the full picture and need a tip… Thanks!
    p
    • 2
    • 2
  • y

    yahyabayramoglu

    06/18/2019, 12:47 PM
    Is it possible to have multibinding with Koin as intoMap or intoSet functionalities like in Dagger2?
    a
    • 2
    • 8
  • e

    Efe

    06/20/2019, 9:44 AM
    Hey folks, after getting the latest update of android studio I’m getting a suggestion to remove the casting of interfaces in koin module. However if I remove that casting it crashes the application. is there a way to tell android studio that this suggestion is not valid?
    p
    • 2
    • 1
  • e

    Efe

    06/20/2019, 9:45 AM
    here how it looks
    g
    • 2
    • 2
  • l

    LG

    06/20/2019, 10:12 PM
    Hi! I was wondering if there was a performance gap between
    single { ClassA() }  
     // ClassA's using by inject
    And
    single { ClassA(get()) }
    g
    a
    • 3
    • 5
  • y

    yahyabayramoglu

    06/21/2019, 6:55 AM
    In case I do not use the global Koin instance but go with koinApplication (which by naming I assume answer will be no) - is there a way to extend the instance and create a new one?
    a
    • 2
    • 7
  • c

    Chainchelliah

    06/23/2019, 4:08 PM
    Hi @arnaud.giuliani, I don't see any new API update for Room. I need your inputs to test basic CRUD operation using koin-test with latest Koin-2.0.1. Attached my code. I got null pointer exception while executed.
    a
    • 2
    • 3
  • s

    Sergio C.

    06/23/2019, 9:04 PM
    Why is android studio not resolving
    by sharedViewModel()
    ? I have all the dependencies...
    👍 1
    l
    a
    • 3
    • 5
  • h

    Henning B

    06/26/2019, 1:44 PM
    hi there, I have a lot of repitions in my koin log. I wonder if this is normal or pointing to some kind of circular dependency.
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'android.content.Context'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'android.content.Context'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
    I/KOIN: +-- 'my.app.components.data.DataFormatter'
    ...
    the actual output is around three times longer.
    n
    • 2
    • 1
  • w

    Wilhelm Fitzpatrick

    06/27/2019, 6:53 PM
    I'm trying to understand scopes in Koin 2.0.1, and why they have both a name and an ID. The only purpose I can see would be two have multiple instances of a given named scope active at the same time. Which works, but then if you close any one of those scope, the others with the same name (but different ID) are no longer usable. What's the point?
    • 1
    • 1
  • s

    smassive

    07/01/2019, 7:15 AM
    Morning! How do you access to Koin Context from an extension? Looks a lil' bit weird do somwthing like
    KoinJavaComponent.get()
    and too verbose to do a
    StandAloneContext.getKoin().koinContext.get()
    , there are other options?
    n
    a
    • 3
    • 4
  • g

    gammax

    07/05/2019, 4:17 PM
    Regarding MP, there is this PR going on: https://github.com/InsertKoinIO/koin/pull/519
    k
    a
    j
    • 4
    • 25
  • m

    Matt Thompson

    07/09/2019, 2:51 PM
    wondering if anyone has looked into configuring static analysis for koin - e.g. to warn you if you're injecting a class that isn't in your modules
    a
    • 2
    • 3
  • l

    LG

    07/12/2019, 1:10 PM
    Just had a weird behaviour on lint. I have this module, but for some reason the cast as CarsRepository is declared not needed. But it’s actually mandatory otherwise at runtime the application crashes 😮
    val remoteModule = module {
        factory { CarRemoteRepositoryImpl() as CarsRepository }
    }
    How can I debug this from Koin core side?
    n
    • 2
    • 1
  • s

    Sergio C.

    07/14/2019, 12:03 PM
    hello people, What is the androidLogger() used for in the startKoin function?
    v
    • 2
    • 2
  • s

    Sergio C.

    07/14/2019, 12:23 PM
    how do I inject the databaseDAO directly with koin? It says it doesn't have enough information to infer type variable T... Why does it need to be a
    val
    ?
    v
    • 2
    • 2
  • m

    Marko Mitic

    07/15/2019, 2:57 PM
    I'm adding koin to my library, wish me luck
    t
    • 2
    • 3
  • c

    ciriti

    07/20/2019, 7:07 AM
    Hi guys! I've just updated my project with koin 2.0 but I’m not able, during the instrumentation test, to inject my mock object, do you have any suggestion?
    o
    a
    • 3
    • 5
Powered by Linen
Title
c

ciriti

07/20/2019, 7:07 AM
Hi guys! I've just updated my project with koin 2.0 but I’m not able, during the instrumentation test, to inject my mock object, do you have any suggestion?
o

oleg_osipenko

07/21/2019, 2:51 PM
I created a custom test runner, and in the
newApplication()
method inside the runner I submit my test Application, where I provide my test modules
c

ciriti

07/21/2019, 3:24 PM
The thing is that with koin v1 you could avoid creating the custom runner, now looks like you have to, what a pity
a

arnaud.giuliani

07/22/2019, 8:21 AM
if you have any better suggestion to help, don’t hesitate to give feedback
c

ciriti

07/22/2019, 8:50 AM
It will take some time but I can try to contribute to a solution 👍
a

arnaud.giuliani

07/22/2019, 3:46 PM
great 👍
View count: 4