holgerbrandl / kalasim

Discrete Event Simulator
https://www.kalasim.org/
MIT License
69 stars 10 forks source link

java.lang.IllegalStateException: KoinApplication has not been started #14

Closed sboishtyan closed 2 years ago

sboishtyan commented 3 years ago

kalasim 0.6.6

fun main() {
    val devices = Resource(name = "devices", capacity = 1)
}
Exception in thread "main" java.lang.IllegalStateException: KoinApplication has not been started
    at org.koin.core.context.GlobalContext.get(GlobalContext.kt:35)
    at org.kalasim.Resource.<init>(Resource.kt:42)
    at MainKt.main(Main.kt:7)
    at MainKt.main(Main.kt)

How could I start KoinApplication?

holgerbrandl commented 3 years ago

You would need to create a simulation context before instantiating the resource. E.g. with

Environment().apply{
  val devices = Resource(name = "devices", capacity = 1)
}

For more details regarding koin and dependency injection see https://www.kalasim.org/basics/#dependency-injection

Feel welcome if you have further issues.

holgerbrandl commented 2 years ago

I've adjusted the docs accordingly