https://kotlinlang.org logo
#koin
Title
# koin
s

spechard

01/31/2023, 8:48 PM
Hi, I try to understand if scope is suitable to what I wanna do, but I can’t make this simple example to work. Can anyone help me making this test run successfully (see thread). Thanks a lot!
Copy code
@Test
    fun test() {
        startKoin {
            module {
                scope(named("first")) {
                    scoped { Example(name = "example") }
                }
            }
        }

        val scope = getKoin().createScope("id", named("first"))
        val example = scope.get<Example>()
        assertEquals("example", example.name)

        stopKoin()
    }

    data class Example(val name: String)
Hi @arnaud.giuliani, do you have any advice on this? Thanks
a

arnaud.giuliani

02/07/2023, 12:55 PM
in what is it failing?
s

spechard

02/07/2023, 3:45 PM
I get the following error:
Copy code
NoBeanDefFoundException: No definition found for class:'...Test$Example' q:''. Check your definitions!
I thought I could get the scope with
createScope
and
named
, but it doesn’t seem to work
Maybe it’s a detail, but the test is in the
jvmTest
part of a multiplatform project
a

arnaud.giuliani

02/07/2023, 4:06 PM
you forgot the
modules()
function inside startKoin:
then it’s loading nothing 😄
s

spechard

02/07/2023, 4:07 PM
damn, I’m that stupid?
Thanks for your help, I’m so sorry to have disturb you for such a ridiculous error 😅
a

arnaud.giuliani

02/07/2023, 4:20 PM
No problem 👍 The DSL builders are not safe from everywhere
s

spechard

02/07/2023, 4:23 PM
Well, it works very well in all my other tests (and production code), but I’m not very familiar with scopes, and I think it’s what I need at the moment, so I tend to doubt more easily 😄
10 Views