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

    Udit003

    12/30/2018, 7:41 AM
    Hello folks, I am seeing a weird behaviour by Koin-Android Viewmodel. I have a main Activity with bottom navigation. The bottom navigation tabs
    replaces
    Fragments. I have created global instances of fragments in the activity (in order not to re-instantiate the fragments again on tab change). Now once a fragment is loaded and replaced (on tab change),its complete lifecycle is called (from
    onAttach()
    to
    onDestroy()
    and
    onDetach()
    ). So I expected the viewmodel of the fragment to also get destroyed and
    onCleared()
    called once the
    onDestroy()
    of the fragment is called. Also new viewmodel should be instantiated when fragments is created again. But it is not happening as expected. The viewmodel is only created once and
    onCleared()
    is only called the first time
    onDestroy()
    of the fragment is called. I tested it using the following code :
    class HomeViewModel : ViewModel() {
    
        init {
            Log.d("Fragment_Checker","Viewmodel_INIT")
        }
    
        private var counter = 1
    
    
        fun getCounter():Int{
            counter++
            return counter
        }
    
        override fun onCleared() {
            Log.d("Fragment_Checker","ViewModel_Destroyed")
            super.onCleared()
        }
    }
    
    /*Fragment class */
    
    class HomeFragment : androidx.fragment.app.Fragment() {
    
        val viewModel: HomeViewModel by viewModel()
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            Log.d("Fragment_Checker","onCreate")
     
        }
        override fun onResume() {
            super.onResume()
            Log.d("Fragment_Checker","Counter "+viewModel.getCounter())
        }
    
        override fun onDetach() {
            super.onDetach()
            Log.d("Fragment_Checker","onDetach")
        }
        override fun onDestroy() {
            super.onDestroy()
            Log.d("Fragment_Checker","onDestroy")
        }
    The log output looks like : onCreate Viewmodel_INIT Counter 2 //tab changed ViewModel_Destroyed onDestroy onDetach //move back to home tab onCreate Counter 3 //tab changed onDestroy onDetach
    n
    o
    • 3
    • 9
  • p

    poohbar

    12/31/2018, 2:01 PM
    Do I need the
    koin-ktor
    package? What does it add over
    koin-core
    ?
    s
    • 2
    • 1
  • a

    amatkivskiy

    01/02/2019, 11:45 AM
    Hi @arnaud.giuliani, do you know wether
    ViewModel
    can have another ViewModel as constructor dependency ? Something like this
    viewModel { BasketViewModel(get()) }
    viewModel { SelectProductViewModell(get(),  basketViewModel) }
    k
    • 2
    • 7
  • n

    nwh

    01/04/2019, 9:33 PM
    How can I make koin compatible with instant reloading on Android? I have the module definition in the
    onCreated
    of my Activity right now, and it errors due to re-declaration of singles
    a
    • 2
    • 2
  • p

    Pavel.AZ

    01/06/2019, 12:30 PM
    Hello ! how to use same dependency "single" for a few modules?
    a
    • 2
    • 3
  • g

    gmariotti

    01/07/2019, 12:15 PM
    I’ve created a small example using #koin and #vertx, let me know what you think https://github.com/vert-x3/vertx-examples/pull/326
    a
    • 2
    • 1
  • c

    ciriti

    01/07/2019, 5:49 PM
    Hi guys! Using the following module declaration val module = module{ viewModel { MyModule(get()) } // MyModule extends ViewModule } The MyModule object gets created every time it is injected even when I rotate the device. It also doesn’t follow the activity lifecycle, did I do any mistake during the configuration?
    n
    • 2
    • 2
  • g

    gaspard

    01/14/2019, 9:35 PM
    I have a problem using koin, mockito and android studio: I am doing something very similar to this example: https://github.com/InsertKoinIO/getting-started-koin-core/blob/master/src/test/kotlin/org/koin/sample/HelloMockTest.kt but the declareMock() function is unresolved (even when using the full qualified name) and the "by inject" keep asking for a clazz parameter. I m using org.koin:koin-test:1.0.2 and org.koin:koin-android:1.0.1 and org.koin:koin-java:1.0.0-RC-1 (for legacy Java code)
    a
    j
    • 3
    • 2
  • a

    arnaud.giuliani

    01/25/2019, 2:51 PM
    new website updates 👉 https://beta.insert-koin.io/
    👍 1
    g
    • 2
    • 7
  • s

    smassive

    01/31/2019, 10:33 AM
    @arnaud.giuliani hi! how safe is it using beta version on production?
    a
    • 2
    • 9
  • g

    gumil

    02/04/2019, 10:52 AM
    How is Koin handling viewmodels? when does the viewmodel initialized and destroyed?
    y
    • 2
    • 2
  • v

    Vinicius Carvalho

    02/04/2019, 3:39 PM
    Hi all is it possible to register shutdown hooks on beans created by koin? During my application shutdown I'd like to some of my beans to have a method invoke to clean up resources
    a
    • 2
    • 16
  • b

    bastienC

    02/06/2019, 12:34 PM
    Hi ! Having troubles with koin on generic declaration, for example :
    single<BaseCmsMapper<OnClickHodor?, OnClick>>(name = "onClickMapper") {
            OnClickMapper(errorDispatcher = get(), templateMapper = get("templateMapper"))
        }
    onClickMapper dependency is used just below like :
    single<BaseCmsMapper<SeasonHodor, Season>>(name = "seasonMapper") {
            SeasonMapper(errorDispatcher = get(), onClickMapper = get("onClickMapper"))
        }
    returned error is :
    2019-02-06 12:26:02.392 18700-18700/? E/KOIN: [ERROR] - Error while resolving instance for class 'com.canal.android.mycanalpoc.cms.common.BaseCmsMapper' - error: org.koin.error.NoBeanDefFoundException: No compatible definition found. Check your module definition 
    2019-02-06 12:26:02.395 18700-18700/? E/KOIN: [ERROR] - Error while resolving instance for class 'com.canal.android.mycanalpoc.cms.common.BaseCmsMapper' - error: org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='onClickMapper',class='com.canal.android.mycanalpoc.cms.common.BaseCmsMapper']' due to error :No compatible definition found. Check your module definition
    Any idea?
    • 1
    • 1
  • a

    arnaud.giuliani

    02/06/2019, 1:38 PM
    yeah, generic types are not handled. Prefer go with some holder type instead
    b
    • 2
    • 13
  • a

    Alan Evans

    02/06/2019, 1:55 PM
    certainly caught me out before, do you think registration of generics could be made illegal?
    a
    • 2
    • 20
  • p

    peterG

    02/07/2019, 8:13 AM
    Hi guys. I have a question regarding reloading of modules. In my app I have a base module where the application class is located which starts koin. Than I have a couple of (feature) modules depending on the base module but do not know anything about each other. Now I have a library with where the users login is handled (in a singleton class). I need the same instance in both feature modules but when I try to load the same module twice, koin is telling me, that the definitions already exists and the app crashes. So the question is, how can I (re)load this "account" module without crashing the app? (To declare the modules in the base module is no option for me)
    a
    • 2
    • 9
  • k

    kenkyee

    02/11/2019, 9:29 PM
    but Android Studio (3.4 or 3.5) can't find the class or package
    • 1
    • 1
  • a

    arnaud.giuliani

    02/18/2019, 7:54 AM
    did you checked: https://beta.insert-koin.io/docs/2.0/quick-references/koin-for-android/#extended-scope-api-for-android-koin-android-scope-or-koin-androidx-scope-projects
    k
    • 2
    • 5
  • g

    gergo

    02/18/2019, 2:26 PM
    👋 hello, i'm migrating my application from dagger to koin and I am thinking is there a similar solution to dagger Provider<T>? Basically injecting a factory which can create T objects with it's dependencies provided by koin.
    s
    • 2
    • 3
  • m

    Maikals

    02/20/2019, 7:39 AM
    Good morning@arnaud.giuliani, Some weeks ago I updated Koin to the beta version and it's incredible. It's really fast creating instances, congrats!!
    👍 1
    a
    • 2
    • 1
  • a

    Alex

    02/21/2019, 11:42 AM
    Hi, I am testing my modules like this
    class ModulesTest : KoinTest {
    
        @Test
        fun checkAllModules() {
            koinApplication { modules(listOf(coreModule, appModule, roomModule, moshiModule)) }.checkModules()
        }
    }
    but I am getting the following error:
    org.koin.core.error.NoBeanDefFoundException: No definition found for 'android.content.Context' has been found
    I know it is because my room module is using
    androidApplication()
    but I don't know how to fix it. Any ideas please??
    a
    • 2
    • 2
  • a

    Alex

    02/21/2019, 11:45 AM
    also, we are having some discussions on the office whether we should use Koin or Dagger2 for a new project. We have started with Koin and I would like to stick to it, but some of my workmates think it won't escalate well on big projects. Has somebody tried Koin on big projects? Could somebody provide some insights on this escalation problems? thanks!
    a
    • 2
    • 9
  • o

    orogersilva

    02/21/2019, 6:30 PM
    @arnaud.giuliani, can you help me with this issue?
    a
    • 2
    • 9
  • a

    arnaud.giuliani

    02/26/2019, 8:34 AM
    very simple sample
    s
    • 2
    • 1
  • k

    kenkyee

    02/28/2019, 9:46 PM
    in the Koin declaration, it's initialized like this: single { MutableLiveData<LoginState>() }
    a
    d
    • 3
    • 5
  • k

    kenkyee

    03/04/2019, 6:46 PM
    FYI, When doing Koin JUnit tests, I found that I had to call stopKoin() before startKoin(). startKoin is called from the @Setup of the unit tests. Otherwise, it'd complain that the koin application is already started when startKoin() is called. Don't see this mentioned in the docs anywhere...
    1️⃣ 1
    😥 1
    a
    • 2
    • 3
  • s

    Sergio Crespo Toubes

    03/06/2019, 11:43 AM
    Hello, how can i do this example with koin? https://github.com/googlesamples/android-architecture/blob/todo-mvp-clean/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailActivity.java How can i inject the string extra
    EXTRA_TASK_ID
    with koin?
    s
    • 2
    • 2
  • a

    arnaud.giuliani

    03/13/2019, 3:12 PM
    problem is that ON_DESTROY is not send when opening next Activity
    k
    • 2
    • 4
  • v

    Vinicius Carvalho

    03/13/2019, 5:24 PM
    @arnaud.giuliani I'm trying to build master, to make a PR actually and there seems to be a build error on koin-ktor
    a
    • 2
    • 10
  • n

    nwh

    03/13/2019, 7:03 PM
    Is it possible to inject a single mocked dependency into Koin? On Android, I'm using Robolectric, which uses the Application's module. I just want one of its dependencies to be overriden in certain situations
    a
    • 2
    • 2
Powered by Linen
Title
n

nwh

03/13/2019, 7:03 PM
Is it possible to inject a single mocked dependency into Koin? On Android, I'm using Robolectric, which uses the Application's module. I just want one of its dependencies to be overriden in certain situations
a

arnaud.giuliani

03/13/2019, 8:52 PM
have you check the
declareMock
function in koin-test?
☝️ 1
n

nwh

03/13/2019, 8:54 PM
I am ashamed to say I didn't realize I didn't have the koin-test module 🤦‍♂️🏻 thank you!
View count: 2