question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

createAtStart should also work when loadKoinModules() is called

See original GitHub issue

Is your feature request related to a problem? Please describe.

In our application we create a bare-bones KoinApplication that knows just enough to assess and setup a local environment to get it into a stable, well known state. Once in that known state, then more modules are loaded, based on the conditions of what happened in the assessment/setup phase. It looks like this:

        val bootstrapModule = module {
            single { AAA(get()) }
            single { BBB() }
            single(createdAtStart = true) { CCC(get()) }
        }
        startKoin {
            modules(bootstrapModule)
        }

        val moduleDDD = buildDDDModule( ... using AAA, BBB or CCC ... )
        val moduleEEE = module {
          single(createdAtStart = true) { ZZZ() }
        }
        val moduleFFF = module { ... }
        loadKoinModules(listOf(
          moduleDDD,
          moduleEEE,
          moduleFFF
        ))

The problem is that ZZZ does not get created when loadKoinModules is called. When ZZZ is something that we want to “fail fast”, we won’t know there is a problem until it gets instantiated later.

Describe the solution you’d like

The desired behavior is to have loadKoinModules() honor the createAtStart flag. The meaning of createAtStart would perfectly fit with the intent.

Describe alternatives you’ve considered

The current workaround is to place some dummy code that calls upon ZZZ early in the application.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
arnaudgiulianicommented, Oct 8, 2020

added createEagerInstances parameter to loadModules function, in Koin 2.2.0

1reaction
iamriajulcommented, Feb 14, 2021

added createEagerInstances parameter to loadModules function, in Koin 2.2.0

Can you please give me an example for Android?

I’m trying this way, but it’s an internal function getKoin().createEagerInstances()

I have seen that KoinApplication has the createEagerInstances method as public, but I couldn’t find a way to get the current KoinApplication instance!

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Start Koin
The startKoin function is the main entry point to launch Koin container. It need a list of Koin modules to run. Modules are...
Read more >
CHANGELOG.md · Gitee 极速下载/koin - Gitee.com
Please use modules(modules: List<Module>); [BREAKING] - loadKoinModules(vararg modules: Module) in GlobalContext has been removed for performance reasons.
Read more >
Koin: Lightweight Dependency Injection Framework
A practical introduction to Koin - lightweight dependency injection framework for Kotlin.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found