Hi, I try to understand if scope is suitable to wh...
# koin
s
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
in what is it failing?
s
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
you forgot the
modules()
function inside startKoin:
then it’s loading nothing 😄
s
damn, I’m that stupid?
Thanks for your help, I’m so sorry to have disturb you for such a ridiculous error 😅
a
No problem 👍 The DSL builders are not safe from everywhere
s
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 😄