John O'Reilly
09/22/2024, 2:26 PMKoinApplication has not been started starting say Compose for DesktopWeb clients after updating....John O'Reilly
09/22/2024, 2:29 PMException in thread "main" java.lang.IllegalStateException: KoinApplication has not been started
at org.koin.core.context.GlobalContext.get(GlobalContext.kt:36)
at org.koin.core.context.GlobalContext.loadKoinModules(GlobalContext.kt:70)
at org.koin.core.context.KoinContext$DefaultImpls.loadKoinModules$default(KoinContext.kt:58)
at org.koin.core.context.DefaultContextExtKt.loadKoinModules(DefaultContextExt.kt:50)
at dev.johnoreilly.climatetrace.di.KoinKt.commonModule$lambda$8(Koin.kt:34)
and difference I think in this project is call to loadKoinModules in following
fun commonModule(enableNetworkLogs: Boolean = false) = module {
single { createJson() }
single { createHttpClient(get(), enableNetworkLogs = enableNetworkLogs) }
single { ClimateTraceApi(get()) }
single { CountryListViewModel() }
single { CountryDetailsViewModel() }
single { ClimateTraceRepository(get(), get()) }
loadKoinModules(dataModule())
}John O'Reilly
09/22/2024, 2:33 PMkstore was setup? I tried approach I used in other projects where I used something like following and seem to run in to other (runtime) isssues
startKoin {
appDeclaration()
modules(commonModule(enableNetworkLogs = enableNetworkLogs), dataModule())
}pitpit
09/23/2024, 7:14 AMKoinApplication(application = { modules(appModule, platformModule, databaseModule, viewModelModule) }) {arnaud.giuliani
09/23/2024, 3:50 PMJohn O'Reilly
09/23/2024, 6:42 PM@Composable
fun App() {
KoinApplication(application = {
modules(commonModule())
}) {
MaterialTheme {
Navigator(screen = ClimateTraceScreen())
}
}
}arnaud.giuliani
09/23/2024, 7:32 PMJohn O'Reilly
09/23/2024, 7:45 PMJohn O'Reilly
09/23/2024, 7:46 PMpitpit
09/24/2024, 7:06 AMloadKoinModules(dataModule()) by includes(dataModule)xxfast
09/24/2024, 1:54 PMval application = {
modules(dataModule)
}
expect val dataModule: Module
// on wasmJsMain / jsMain
actual val dataModule: Module get() = module {
single<KStore<List<Country>>{ storeOf(key = "countries", default = emptyList()) }
}
And yeah, looks like i might've used the wrong koin api to load different modulesarnaud.giuliani
09/24/2024, 2:08 PMloadKoinModules?xxfast
09/24/2024, 2:10 PMincludes()arnaud.giuliani
09/24/2024, 2:57 PMJohn O'Reilly
09/24/2024, 4:49 PMincludes but run in to some other runtime error then....I'll keep diggingJohn O'Reilly
09/24/2024, 4:54 PMjava.lang.IllegalStateException: KoinApplication has not been started
at org.koin.core.context.GlobalContext.get(GlobalContext.kt:36)
at org.koin.core.component.KoinComponent$DefaultImpls.getKoin(KoinComponent.kt:33)
at dev.johnoreilly.climatetrace.viewmodel.CountryListViewModel.getKoin(CountryListViewModel.kt:21)
this is for
open class CountryListViewModel : ViewModel(), KoinComponent {
private val climateTraceRepository: ClimateTraceRepository by inject()
Could likely be something wrong I have in my setupJohn O'Reilly
09/24/2024, 4:58 PMfun App() {
KoinApplication(application = {
modules(commonModule())
}) {
MaterialTheme {
Navigator(screen = ClimateTraceScreen())
}
}
}
ClimateTraceScreen.kt
class ClimateTraceScreen: Screen {
@Composable
override fun Content() {
val countryListViewModel = koinInject<CountryListViewModel>()
val countryListViewState by countryListViewModel.viewState.collectAsState()
CountryListViewModel.kt
open class CountryListViewModel : ViewModel(), KoinComponent {
private val climateTraceRepository: ClimateTraceRepository by inject()
Koin.kt
fun commonModule(enableNetworkLogs: Boolean = false) = module {
single { createJson() }
single { createHttpClient(get(), enableNetworkLogs = enableNetworkLogs) }
single { ClimateTraceApi(get()) }
single { CountryListViewModel() }
single { CountryDetailsViewModel() }
single { ClimateTraceRepository(get(), get()) }
includes(dataModule())
}John O'Reilly
09/24/2024, 5:03 PMKoinComponent then it works (but then have issues in iOS client) where CountryListViewModel is instantiated directly atmarnaud.giuliani
09/25/2024, 7:04 AMJohn O'Reilly
09/25/2024, 7:25 AMJohn O'Reilly
09/25/2024, 7:26 AMincludes instead of loadKoinModules that was used before ....that gets past initial issue we had but then run in to the other one mentioned above that seems related to use of KoinComponentJohn O'Reilly
09/25/2024, 7:26 AMarnaud.giuliani
09/25/2024, 10:27 AMarnaud.giuliani
09/27/2024, 4:09 PMJohn O'Reilly
09/27/2024, 4:13 PMmain.kt in desktopMain you can run main there from IDEJohn O'Reilly
09/27/2024, 4:13 PMJohn O'Reilly
09/27/2024, 4:21 PMarnaud.giuliani
09/27/2024, 4:23 PMarnaud.giuliani
09/27/2024, 4:30 PMJohn O'Reilly
09/27/2024, 4:31 PMarnaud.giuliani
09/27/2024, 4:39 PMJohn O'Reilly
10/16/2024, 4:51 PMarnaud.giuliani
10/16/2024, 5:06 PMarnaud.giuliani
10/16/2024, 5:16 PMarnaud.giuliani
10/16/2024, 5:17 PMarnaud.giuliani
10/16/2024, 5:17 PMJohn O'Reilly
10/16/2024, 5:18 PMarnaud.giuliani
10/16/2024, 5:18 PMJohn O'Reilly
10/16/2024, 5:26 PMCountryListViewModel to not use KoinComponent ....and injected dependency through constructor instead
open class CountryListViewModel(val climateTraceRepository: ClimateTraceRepository) : ViewModel() { //} KoinComponent {
//private val climateTraceRepository: ClimateTraceRepository by inject()John O'Reilly
10/16/2024, 5:31 PMKoinApplication has not been started somewhere before....John O'Reilly
10/16/2024, 5:34 PMarnaud.giuliani
10/16/2024, 6:31 PMarnaud.giuliani
10/18/2024, 9:11 AMClimateTraceRepository is not in constructor? I see a race condition here about it being in by inject delegate fieldarnaud.giuliani
10/18/2024, 9:11 AMKoinApplication composable that don't register well the default context here π€arnaud.giuliani
10/18/2024, 9:12 AMKoinComponent hereJohn O'Reilly
10/18/2024, 9:20 AMarnaud.giuliani
10/18/2024, 9:33 AMarnaud.giuliani
10/18/2024, 9:33 AMarnaud.giuliani
10/18/2024, 3:01 PMarnaud.giuliani
10/18/2024, 3:01 PMJohn O'Reilly
10/18/2024, 3:02 PMarnaud.giuliani
10/25/2024, 1:31 PMarnaud.giuliani
10/25/2024, 1:31 PMJohn O'Reilly
10/25/2024, 1:31 PMJohn O'Reilly
11/29/2024, 12:23 PMarnaud.giuliani
11/29/2024, 12:29 PM