Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated modules are global #92

Closed
lukelast opened this issue Sep 29, 2023 · 6 comments
Closed

Generated modules are global #92

lukelast opened this issue Sep 29, 2023 · 6 comments
Assignees
Labels
question Further information is requested type:improvement
Milestone

Comments

@lukelast
Copy link

Is your feature request related to a problem? Please describe.
I'm trying to create many instances of KoinApplication to use in tests that run in parallel. Currently this not possible because the generated module instances are set in global variables.

For example, code like this:

@Module
@ComponentScan("blah")
class ScanModule

Will generate code like this:

public val foo_ScanModule : Module = module {
    single() { Blah() }
}
public val ScanModule.module : org.koin.core.module.Module get() = foo_ScanModule

The foo_ScanModule keeps a single global instance of the module, which causes singletons to be shared among all koin instances created with this module.

Describe the solution you'd like
I think calling ScanModule.module should create a new instance of the module each time.

@undermark5
Copy link

Is it ever necessary to reference the module outside of instantiating Koin/multiple times? If so, couldn't this proposal cause problems? I'm not certain that referencing a module multiple times is ever needed, so this may not actually cause any problems.

@lukelast
Copy link
Author

lukelast commented Oct 9, 2023

I see 2 options for implementing a fix.

  1. Change the existing ScanModule.module to return a new instance of the module each time.
  2. Keep the current behavior, but allow access to get new instances of the module. Like ScanModule.createModule()

Either would work for me. With option 1 you can still create and use a global module that would be shared across multiple koin instances, you would just have to do it explicitly.

@arnaudgiuliani arnaudgiuliani added question Further information is requested type:improvement labels Oct 31, 2023
@arnaudgiuliani
Copy link
Member

Ok interesting 🤔 need to check the global impact of this

@arnaudgiuliani arnaudgiuliani self-assigned this Oct 31, 2023
Copy link

stale bot commented Mar 30, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status:wontfix This will not be worked on label Mar 30, 2024
@lukelast
Copy link
Author

lukelast commented Apr 2, 2024

You're breaking my heart stale bot.

@arnaudgiuliani
Copy link
Member

duplicated with #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested type:improvement
Projects
None yet
Development

No branches or pull requests

3 participants