Skip to content

Support unloadKoinModules() for Lazy modules - #2460

Open
cpaleop wants to merge 2 commits into
InsertKoinIO:mainfrom
cpaleop:main
Open

Support unloadKoinModules() for Lazy modules#2460
cpaleop wants to merge 2 commits into
InsertKoinIO:mainfrom
cpaleop:main

Conversation

@cpaleop

@cpaleop cpaleop commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Linked issue: #2459

This PR provides support for unloading LazyModules out-of-the-box.

The existing API (unloadKoinModules(modules: List<Module>)) can also be used for this, but it requires maintaining initialization/realization logic on consumer side. More about that in the linked issue.

* No-op if the lazy module has not been initialized yet, since in that case
* no definitions were ever registered for it.
*
* @author Chris Paleopanos

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the authors are now mentioned in a disconnected kDoc right after the class signature. This doesn't make sense, so I added it here.

Let me know though if you want me to move it above 🙏🏻

*
* @author Chris Paleopanos
*/
fun loadKoinModules(modules: List<Lazy<Module>>) = KoinPlatformTools.defaultContext().loadKoinModules(modules.map { it.value })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added support for this overload, just to keep parity between eager and lazy APIs

class UnloadTarget
class UnloadTarget2

class LoadLazyModulesTest {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to test the case where:

  • App calls unloadKoinModules(..)
  • Some of the Lazy modules have not been initialized yet
  • Verify that only the initialized modules are being unloaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant