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

    LeoColman

    07/22/2019, 3:12 PM
    If you guys want, I can put this integration close to the JUnit guide at Koin's Documentation
    👍 5
    a
    • 2
    • 1
  • p

    Paulius Ruminas

    07/23/2019, 6:24 AM
    Hello, since dependencies are resolved at runtime is there a way to write a test that tries to resolve all of the registered classes in the container?
    o
    • 2
    • 2
  • g

    gvetri

    07/25/2019, 1:19 PM
    Hi everyone, is there an alternative to
    androidContext(this@MainApplication)
    in Java?. I actually have this
    KoinApplication koinApp = KoinApplication.create()
                    .printLogger()
                    .modules(modules);
            start(koinApp);
    I’m actually using the 2.0.1 version
    a
    m
    • 3
    • 5
  • a

    A Gamal

    07/31/2019, 12:52 PM
    Hi, is there any Koin package for Xamarin, or even in progress?
    m
    a
    • 3
    • 5
  • n

    Nir Golan

    08/01/2019, 6:43 PM
    Hey all. I use koin v2 and need to inject context. Any help? New to di
    v
    l
    • 3
    • 2
  • r

    ritesh

    08/06/2019, 7:44 AM
    I am sure, it will throw it for every other dependencies not just
    okHttpClient
    as it's trying to override the second time. And not able to create 2 different instance. Any help would be appreciated!! @arnaud.giuliani
    m
    a
    • 3
    • 11
  • l

    LeoColman

    08/06/2019, 8:46 PM
    Do Koin support something like "Get all implementations of this class"
    r
    m
    +2
    • 5
    • 18
  • r

    Rohil Chodankar

    08/08/2019, 9:56 AM
    Hey @arnaud.giuliani and @Marko Mitic, me and @ritesh work on the same project. Here is our use case We are working on a library project that will be used by other application. One of the application needs to have two instances of the our SDK based on the configuration. Both the instance need to be in memory at that same time. We have an initialization class that creates the KoinApplication instance and loads the module. Consider that we have an activity and using koin we inject a viewModel. Now the ViewModel is based on the configuration Object passed by the consuming application. So We need different view model based on each configuration Object With 2.X Koin we have Activity implementing the KoinComponent but how should we inform Activity which KoinApplication to use so that it returns the correct koin instance
    m
    r
    • 3
    • 27
  • r

    ritesh

    08/12/2019, 6:25 AM
    @Marko Mitic @arnaud.giuliani Wondering how to provide context in unit test when doing
    checkModules()
    in 2.x version. CheckModule fails, because it's not able to create context dependent dependency. I have tried giving mockedContext using
    Mockito
    and
    mocck
    to
    startKoin
    dsl, but no luck.
    g
    • 2
    • 3
  • i

    igor.wojda

    08/12/2019, 7:48 AM
    Does the
    Koin
    has some default callback in case when binding was not found? (equivalent of
    Kodein ExternalSource
    https://kodein.org/Kodein-DI/?6.3/core#_external_source)
    a
    • 2
    • 5
  • o

    Ove Stoerholt

    08/16/2019, 7:38 AM
    Here is my test setup:
    class Dummy
    
    class MyTest : KoinTest {
    
        @Test
        fun `should inject my components`() {
            startKoin {
                modules(
                        module {
                            scope(named("dillA")) {
                                scoped { Dummy() }
                            }
    
                        })
            }
    
            val scope = getKoin().getOrCreateScope("dill", named("dillA"))
    
            val scopeDummy = get<Dummy>()
            assertThat(scopeDummy).isNotNull
        }
    }
    • 1
    • 1
  • f

    Filip Zych

    08/18/2019, 3:44 PM
    Hi, I am trying to test a fragment with roboelectric and I can’t get rid of an error :
    org.koin.core.error.InstanceCreationException: Could not create instance for ... view model
    and 3 other defined single<….>{} in the module. In Roboelectric in the @Before I start the Koin with android context and use loadKoinModules(module). I found some answers on stack overflow and I made sure everything is public but with no success. In fragment I am using sharedViewModel if it changes anything.
    r
    • 2
    • 2
  • l

    LeoColman

    08/20/2019, 11:35 PM
    Do you need any help on moving #496 forward?
    a
    • 2
    • 4
  • c

    Cody Engel

    08/29/2019, 2:57 PM
    Hey everyone 👋🏻 we’re trying out Koin for a project and are coming from Dagger 2. I’m wondering if there is any equivalent for
    @Inject constructor(...)
    in Koin? I’d like to avoid defining every dependency in modules/components but unsure if that’s possible.
    c
    m
    a
    • 4
    • 11
  • m

    maddy

    08/30/2019, 6:33 AM
    Hi all. Is there a way for me to pass a variable to a module when initializing it in startKoin? Use case -> I have a library that provides login screen for multiple applications. It needs a different API url for each application, which is used in providing the Retrofit service singleton by Koin. Is there a way for me to achieve this?
    c
    • 2
    • 3
  • g

    gvetri

    09/03/2019, 1:52 PM
    Hi all! i’ve been reading this documentation (https://insert-koin.io/docs/2.0/getting-started/junit-test/) in which the quote says:
    For each test, we start startKoin() and close Koin context closeKoin().
    But closeKoin() cannot be resolved. I saw in the source code the AutoCloseKoinTest and it use stopKoin instead is it a typo in the documentation? Or it’s an error from my part?
    a
    • 2
    • 3
  • d

    David Hackro

    09/03/2019, 10:49 PM
    Hi everyone! Currently im starting with
    Koin
    , and have the next questions. What its the most recommended option for using
    Koin
    in project with dynamic features? for example, i have some modules (dynamic) and i need interaction between they, in big project is a problem with
    scalability
    and
    maintainability
    ? thanks for reading me 😬
    a
    • 2
    • 7
  • h

    Henning B

    09/04/2019, 8:39 AM
    Hi there! I want to write some JUnit tests for a class which injects some dependencies via Koin. I want to mock these dependencies and deliver them via Koin. In my test class I did the following: * I implement the
    KoinTest
    interface * create the mock * create a Koin module with the mock inside * at setup I start Koin The output is as follows:
    [DEBUG] [Koin] instances started in 0.024431 ms
    [DEBUG] [Koin] +- get 'xyz.application.LocalizationHelper'
    
    org.koin.core.error.NoBeanDefFoundException: No definition found for 'xyz.application.LocalizationHelper' has been found. Check your module definitions.
    Am I doing something wrong or isn't it possible to inject mocks that way? If not, what would be the best practice to achive what I want via Koin? Thanks a lot!
    g
    • 2
    • 6
  • a

    arnaud.giuliani

    09/11/2019, 2:50 PM
    Next release will be
    2.1.0
    , gathering all contributions and fixes.I squeeze 2.0.2 to run all on 2.1.0. Still looking if any urgent fix to add (if you seen one, you can ping here) 👍
    n
    • 2
    • 3
  • r

    ritesh

    09/20/2019, 11:57 AM
    I was struggling with fixing the dryRun Test after I had upgraded my koin to 2.x. As there was some problem with context, and koin was not able to create context dependent dependencies. I mocked all the relevant ones and got it working. Now, I run into a problem, when koin tries to create
    retrofit
    when i do
    checkModules
    it throws up
    Method getMainLooper in android.os.Looper not mocked.
    As my retrofit builder by default created with
    .io scheduler
    , i tried adding trampoline, or removing it. Or custom rules for it to do it on the current thread. But no luck. Wondering, if any one else had faced the same.
    o
    • 2
    • 3
  • e

    emmanuelvinas

    09/24/2019, 12:39 PM
    hi, quick question. What's the Koin's way of having multiple instance in the app. For example Mock implementations and real implementations and loading one or the other depending on something at runtime ?
    a
    • 2
    • 9
  • p

    Piotr Prus

    09/26/2019, 1:19 PM
    Hi, I am trying to inject class into java class using koin. Is it possible? I tried to find some documentation about that online, but found nothing 😞
    d
    • 2
    • 12
  • k

    kvnxiao

    09/26/2019, 5:26 PM
    Hey all, Is there an easy way of declaring a "list" of `single`s for a module? I wish to create a list of dependencies to be injected with
    getAll
    , and care not for the qualifier. Was hoping there was an easier way rather than defining a different qualifier each time as I have over 10 different classes in the list
    c
    • 2
    • 2
  • v

    voben

    09/28/2019, 5:05 PM
    I'm trying to defer the initialization of okhttp client to the first network call. I think its possible to do something like this in Dagger. How do I achieve something similar with Koin ?
    @Provides
    fun provideRetrofit(client: Lazy<OkHttpClient>): Retrofit {
        return Retrofit.Builder()
            .callFactory(object : Call.Factory {
                override fun newCall(request: Request): Call {
                    return client.get().newCall(request)
                }
    
            })
            .build()
    }
    a
    • 2
    • 2
  • q

    quver

    10/09/2019, 12:35 PM
    Found a mistake in doc it’s
    import static org.koin.java.standalone.KoinJavaComponent.inject;
    but it’s
    import static org.koin.java.KoinJavaComponent.inject;
    without
    standalone
    v
    • 2
    • 1
  • s

    Sam

    10/11/2019, 11:58 AM
    Hello everyone I read this question
    <https://github.com/InsertKoinIO/koin/issues/471>
    , but not work, so anyone have any solution for generic type ? Thanks
    LoginRepository extends BaseRepository
    
    factory<BaseRepository> { LoginRepository(get()) }
    
    abstract class BaseUseCase<R : BaseRepository> : KoinComponent {
        private val _repository: BaseRepository by inject()
        protected val repository: R
            get() {
                return _repository as R
            }
    }
    a
    • 2
    • 4
  • a

    Artem

    10/11/2019, 1:52 PM
    Hello guys, I’m totally new to koin, not even sure if it’s the proper tool which can assist me in getting shared (singleton?) android ViewModel with arguments. Can you give me some idea how to get a ViewModel(arg1, arg2) as singleton?
    j
    a
    • 3
    • 4
  • v

    Valay

    10/11/2019, 1:54 PM
    I found an example with one argument but no example found with two. It's easy to create in Kotlin. However our code is legacy
    a
    • 2
    • 2
  • s

    Shreyansh Lodha

    10/14/2019, 8:00 AM
    Hey guys, I am new to DI and Koin, I wanted to know if Koin has any alternative to
    @Reusable
    of
    Dagger 2
    a
    • 2
    • 6
  • s

    sajadgarshasbi

    10/15/2019, 6:19 PM
    hi, is possible to use Koin in Android Library? if yes, when i should call startKoin?
    m
    e
    • 3
    • 6
Powered by Linen
Title
s

sajadgarshasbi

10/15/2019, 6:19 PM
hi, is possible to use Koin in Android Library? if yes, when i should call startKoin?
m

Marko Mitic

10/15/2019, 6:22 PM
yes, it's easy to use for android lib. You should initialize koin when you need your app initialized, that depends on your API.
additionally, I suggest using
koinApplication
builder instead of
startKoin
to avoid potential conflicts with apps using koin
👍 2
s

sajadgarshasbi

10/15/2019, 6:45 PM
Thanks, if i use
koinApplication
then `startKoin`does not need to call from any where?
m

Marko Mitic

10/15/2019, 7:08 PM
yes, but you'll need to store result of koinApplication and use it to get needed dependencies
s

sajadgarshasbi

10/15/2019, 7:24 PM
Thank you so much 👍
e

Efe

10/16/2019, 7:25 AM
@sajadgarshasbi here is the documentation link for the context isolation. https://insert-koin.io/docs/2.0/documentation/reference/index.html#_koin_context_isolation
👍 1
View count: 10