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

    Stefan Schmid

    02/28/2022, 12:14 PM
    Hi everyone, I am currently looking at the new features available in koin 3.2.0 (here), but I do not completley understand what is going to be deprecated. What do you mean with Reflection DSL? Will
    get
    and
    getAll
    still be available (and not deprecated)? Thanks for your help!
    a
    • 2
    • 3
  • a

    arnaud.giuliani

    03/01/2022, 8:38 AM
    Koin Annotations is available: https://medium.com/koin-developers/koin-annotations-c06c2b876ebe
    😍 3
    👍 3
    k
    r
    • 3
    • 7
  • v

    Vivek Modi

    03/01/2022, 3:03 PM
    why this multiplatfrom doc is empty in koin https://insert-koin.io/docs/reference/koin-mp/intro
    a
    r
    • 3
    • 5
  • k

    khairil.ushan

    03/02/2022, 8:14 PM
    Hi Everyone, so I’m using Koin in my KMM projet. I do the startKoin when app start (on main thread) and try to access my API from Swift’s
    Task
    (non main thread). It gives me this error
    Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
    It is considered unexpected and unhandled instead. Program will be terminated.
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared org.koin.core.context.GlobalContext.KoinInstanceHolder@126fc48 from other thread
    Anyone know how to work around this issue? Thank you
    a
    • 2
    • 2
  • j

    Jerry Preissler

    03/05/2022, 7:49 PM
    Hi, I'd like to use Koin in my small Ktor project. I'm a bit unsure which version of Koin I should be using. The quickstart page linked from the documentation has "Version: 3.2" at the top, but the link to github goes to the 3.0.1 tag. Is that the one I should be using or would I be better of using 3.2.0-beta-1? There is no quickstart in 3.2.0-beta-1 (yet?) but I guess I could try to replicate what I can see in the examples.
    a
    • 2
    • 4
  • s

    Sumit Sharma

    03/12/2022, 8:02 AM
    Hey devs, Could anybody provide me, the tutorial of koin with Android?
    a
    • 2
    • 1
  • r

    Renaud

    03/27/2022, 7:45 PM
    Hi, this section seems outdated with Koin 3.2. Especially this import
    import
    _static_ org.koin.android.viewmodel.compat.ViewModelCompat.getViewModel;
    is not available anymore. → How do we inject a Koin ViewModel in a Java class using Koin 3.2?
    🆙 1
    j
    • 2
    • 2
  • l

    Lilly

    04/03/2022, 12:08 AM
    Any ideas why I get unresolved reference jupiter, RegisterExtension and Test when running the test? Android Studio does not complain, nothing is marked as unresolved.
    import de.datacollect.protocol.di.protocolModule
    import org.junit.jupiter.api.Test
    import org.junit.jupiter.api.extension.RegisterExtension
    import org.koin.test.check.checkKoinModules
    import org.koin.test.junit5.AutoCloseKoinTest
    import org.koin.test.junit5.mock.MockProviderExtension
    
    
    class CheckModulesTest : KoinTest {
    
        @JvmField
        @RegisterExtension
        val mockProvider = MockProviderExtension.create { clazz ->
    
        }
    
        @Test
        fun verifyKoinApp() {
            checkKoinModules(modules = protocolModule)
        }
    }
    
    build.gradle.kts:
    plugins {
       kotlin("jvm")
       `java-library`
    }
    
    depnedencies {
      // Koin Core features
      implementation "io.insert-koin:koin-core:$koin_version"
      // Koin Test features
      testImplementation "io.insert-koin:koin-test:$koin_version"
      testImplementation "io.insert-koin:koin-test-junit5:$koin_version"
    }
    a
    g
    • 3
    • 3
  • r

    Rafael Costa

    04/06/2022, 11:31 AM
    Hey @arnaud.giuliani. Could you kindly take a look at this issue from my open source library? It is related with Koin annotations and it seems like there may be an issue when using other KSP libraries. I would like to get to the bottom of this, also be sure that it is not something I’m doing wrongly on my side. https://github.com/raamcosta/compose-destinations/issues/89
    a
    • 2
    • 16
  • a

    Austin Pederson

    04/07/2022, 7:07 PM
    Hey has anyone seen any issues with integrating Koin from a KMM library into Android? It builds fine for me, but someone on my team is struggling with a crash on
    initKoin
    where Koin is unable to locate a KMM dependency
    j
    a
    • 3
    • 3
  • r

    Rasmus Plaubor

    04/13/2022, 8:38 AM
    Hi @arnaud.giuliani. Do you know when PR for Ktor 2.0.0 support will be merged? 🙂
    a
    • 2
    • 1
  • b

    bobby

    04/18/2022, 4:26 AM
    hi everyone, I want to ask regarding memory usage between
    single
    and
    factory
    AFAIK,
    single
    is used to create only one instance during the application lifetime, so when there is a request about the class instance, it will receive the same one, and only disposed when the application get terminate. while
    factory
    instance will be created new one every time there is a request with the class, but it’s not clear to me when will it dispose. moreover, there is no explanation (after some research) for the memory usage for those two can someone please explain about the memory usage? really appreciate it my colleague really care about the memory usage, since our app is quite large, we try to save every memory we could thank you
    p
    a
    • 3
    • 18
  • l

    lucapette

    04/18/2022, 8:28 PM
    hey! I wanted to fix a typo on https://insert-koin.io/docs/reference/koin-annotations/annotations (I always fix the typos I can see while reading docs…) but the link to edit the page points to a repo that doesn’t exist (or maybe it’s private?
    a
    • 2
    • 6
  • a

    arnaud.giuliani

    04/19/2022, 8:56 AM
    Koin 3.1.6 🎉 https://blog.kotzilla.io/koin-3-1-6-release-long-term-support/
    ❤️ 2
    🎉 13
    🙌 4
    j
    • 2
    • 3
  • n

    Nathan Kleinschmidt

    04/26/2022, 11:17 PM
    The example Quickstart-Android-ViewModel does not seem to work. I am unable to import the
    get()
    , and the application crashes on startup. Is the documentation incomplete or am I missing something? I am trying this in a minimal Compose app using Koin v. 3.1.6
    val appModule = module {
        // MyViewModel ViewModel
        viewModel { MyViewModel(get()) }
    }
    m
    • 2
    • 5
  • k

    KamilH

    04/28/2022, 5:03 AM
    How to correctly create a dependency with generic type using
    koin-annotation
    project? I have a following declaration in my `Module`:
    @Singleton
    fun allPlayersCache(): Cache<Unit, List<Player>> =
        ExpirableCache(LocalDateTimeCacheValidator())
    
    @Singleton
    fun allPlayersByTourCache(): Cache<Season, List<TeamPlayer>> =
        ExpirableCache(LocalDateTimeCacheValidator())
    but it doesn’t work because it gets generated like that:
    single(qualifier=null) { moduleInstance.allPlayersCache() } 
    single(qualifier=null) { moduleInstance.allPlayersByTourCache() }
    and it reports a following error:
    Caused by: org.koin.core.error.DefinitionOverrideException: Already existing definition for [Singleton:'com.kamilh.utils.cache.Cache'] at com.kamilh.utils.cache.Cache::_root_
    I guess in a classic koin I would need to use
    named
    right? It seems like it’s not available in
    koin-annotation
    a
    • 2
    • 1
  • j

    Jerry Preissler

    04/29/2022, 12:38 PM
    Is there a version of Koin available that can be used with Ktor 2? If yes, where can I find it / some docu on how to migrate?
    a
    • 2
    • 3
  • a

    Ashu

    05/08/2022, 2:36 PM
    Hi Everyone I am starting with Compose Multiplatform and added Koin to my common module. But I was wondering where to write the
    startKoin
    part. Is there any "Application" kind of thing in common module? Again, I just started today so I may not know what I am talking about. Please help.
    j
    • 2
    • 1
  • j

    Jan

    05/09/2022, 9:01 PM
    I just cant use inject here. I have koin ktor installed as you can also see here but if I try to import it, it imports the one frmo KoinJava thing...
    • 1
    • 1
  • j

    John O'Reilly

    05/11/2022, 1:14 PM
    Looking to start adopting new
    singleOf
    in 3.2.0 release. Currently I have likes of following
    single<PeopleInSpaceRepositoryInterface> { PeopleInSpaceRepository() }
        single { PeopleInSpaceApi(get()) }
    PeopleInSpaceApi
    also has 2nd default param (url) which seems to cause an issue if I try following (error below). What's recommended way of dealing with this or is it better to use existing
    single
    for cases like this?.
    singleOf<PeopleInSpaceRepositoryInterface>(::PeopleInSpaceRepository)
        singleOf(::PeopleInSpaceApi)
    could not create instance for [Singleton:'com.surrus.common.remote.PeopleInSpaceApi']: org.koin.core.error.NoBeanDefFoundException: |- No definition found for class:'java.lang.String'. Check your definitions!
    a
    w
    • 3
    • 5
  • a

    arnaud.giuliani

    05/12/2022, 7:17 AM
    Inside Koin 3.2 - The new Koin DSL https://blog.kotzilla.io/inside-koin-3-2-new-dsl/
    :kotlin-intensifies: 10
    h
    • 2
    • 8
  • p

    pitpit

    05/13/2022, 2:10 PM
    Hi where is this : koinNavGraphViewModel ? I'm using koin 3.1.6 but this function not exists
    c
    • 2
    • 3
  • r

    Rak

    05/16/2022, 7:40 AM
    Hi, I have been writing an sdk recently and I decided not to use Koin in the sdk as it would force users to use it as well and provide additional configuration. A similar issue is raised in this reddit post. Any thoughts on embedding Koin inside an sdk without forcing the host app to use it too?
    j
    n
    • 3
    • 6
  • s

    Seb Jachec

    05/16/2022, 11:58 AM
    Hi, I’m using Koin 3.2.0 in a KMM project, targeting Android (Jetpack Compose) and iOS. I’m trying to pass a parameter from Jetpack Compose, through an Android view model, into a common/shared view model that the Android view model depends on. Could anyone point me in the right direction? Common/shared:
    class SharedViewModel(val id: String?)
    
    val sharedModule = module {
    	factoryOf(::SharedViewModel)
    }
    Android:
    class AndroidViewModel(val sharedViewModel: SharedViewModel)
    
    @Composable
    fun MyScreen(
    	id: String?
    ) {
    	val viewModel = getViewModel<AndroidViewModel>(parameters = { parametersOf(id) })
    }
    
    val androidModule = module {
    	// Neither of these work here:
    	// viewModelOf(::AndroidViewModel)
    	// viewModel { params -> AndroidViewModel(get { parametersOf(params.getOrNull()) }) }
    }
    a
    • 2
    • 4
  • m

    Marcin Wisniowski

    05/16/2022, 2:55 PM
    When using Koin Annotations on Android, I am having an issue where after changing build variants the project does not compile, as the generated Koin module from the current variant conflicts with the one generated for the previous build variant. In effect I have to clean the project after switching variants. I believe this is because the Gradle setup, as is in the Readme, adds srcDirs from all variants, not just the current one. How to solve this?
    a
    • 2
    • 2
  • v

    Victor Kabata

    05/18/2022, 8:44 AM
    Hello folks. I'm using Koin v3.2.0 in a Compose desktop project and I am getting a NoClassDefFoundError when I run the project. What could I be doing wrong? desktopApp/.../NotflixDesktop.kt
    lateinit var koin: Koin
    
    fun main() {
    
        koin = initKoin(enableNetworkLogs = false).koin //error here
    
        return application {
            MainScreen(applicationScope = this)
        }
    }
    shared/commonMain/di/Koin.kt
    fun initKoin(enableNetworkLogs: Boolean = false, appDeclaration: KoinAppDeclaration = {}) =
        startKoin {
            appDeclaration()
            modules(commonModule(enableNetworkLogs), platformModule())
        }
    a
    • 2
    • 7
  • f

    Fabian Vorholt

    05/18/2022, 3:13 PM
    Hey, I'm using koin in an android compose app and pass some parameters to some view model. I assumed that the view model will be recreated every time the parameters change because the remember uses
    parameters
    as key in
    ViewModelComposeExt
    :
    return remember(qualifier, parameters) {
            scope.getViewModel(qualifier, { owner }, parameters)
        }
    But actually it isn't like that. It returns the same view model with old parameters. Is that behavior intended? Am I missing something?
    👍 1
    c
    l
    • 3
    • 23
  • u

    Ugurcan Yildirim

    05/27/2022, 8:05 AM
    how can I prevent this?
    a
    • 2
    • 3
  • s

    Seb Jachec

    05/30/2022, 10:18 AM
    Hi, I’m using Koin 3.2.0 in a KMM project, with Jetpack Compose on Android. I’m trying to get a new instance of my view model (
    PageViewModel
    ) based on a parameter, but instead I’m getting the same instance no matter what parameter is provided. Has anyone got any pointers? Simplified/shortened some code as an example: _Android_:
    class PageViewModel(val sharedViewModel: SharedPageViewModel): ViewModel() {}
    
    @Component
    fun ScreenContent(...) {
    	// ...
    	LazyRow(...) {
    		items(...) { PageContent(date = it) }
    	}
    }
    
    @Composable
    fun PageContent(
    	date: LocalDate,
    	viewModel: PageViewModel = getViewModel(parameters = { parametersOf(date) })
    ) {
    	val viewModel: PageViewModel = getViewModel<AndroidViewModel>(parameters = { parametersOf(date) })
    }
    
    val androidModule = module {
    	viewModel { params -> PageViewModel(get { params }) }
    }
    Common/shared:
    class SharedPageViewModel(val date: LocalDate)
    
    val sharedModule = module {
    	factoryOf(::SharedPageViewModel)
    }
    a
    • 2
    • 2
  • a

    alorma

    06/02/2022, 8:01 AM
    Hello! Is it possible to use koin on a ContentProvider :android: ? I'm trying to build a library that uses koin and I want to automatic setup of it (like firebase libraries)
    p
    • 2
    • 1
Powered by Linen
Title
a

alorma

06/02/2022, 8:01 AM
Hello! Is it possible to use koin on a ContentProvider :android: ? I'm trying to build a library that uses koin and I want to automatic setup of it (like firebase libraries)
p

phldavies

06/02/2022, 9:27 AM
Yes it's possible, I did it a few years ago with a KMM SDK project. Unfortunately I don't have access to that codebase any more, but it's possible.
View count: 34