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

Support KSP-generated module to be used in multiple KoinApplication instances #123

Closed
vdshb opened this issue Apr 5, 2024 · 2 comments
Closed
Labels
status:duplicate This issue or pull request already exists

Comments

@vdshb
Copy link

vdshb commented Apr 5, 2024

I believe KSP should generate:

public val package_name_ModuleName : Module get() = module {
	// ... module internals ...
}

instead of

public val package_name_ModuleName : Module = module {
	// ... module internals ...
}

Currently creating two separated KoinApplications with module generated by KSP in the same runtime gives the same beans instead of different instances.

Example of difference:

val fooModule: Module get() = module { single<Foo>() { Foo() } }
val koinApp1 = koinApplication { modules(fooModule) }
val koinApp2 = koinApplication { modules(fooModule) }
val beanFromKoinApp1 = koinApp1.koin.get<Foo>()
val beanFromKoinApp2 = koinApp1.koin.get<Foo>()
//beanFromKoinApp1 and beanFromKoinApp2 are different instances
val fooModule: Module = module { single<Foo>() { Foo() } }
val koinApp1 = koinApplication { modules(fooModule) }
val koinApp2 = koinApplication { modules(fooModule) }
val beanFromKoinApp1 = koinApp1.koin.get<Foo>()
val beanFromKoinApp2 = koinApp1.koin.get<Foo>()
//beanFromKoinApp1 and beanFromKoinApp2 are the same instance
@Jadarma
Copy link

Jadarma commented Apr 30, 2024

Yes, the current implementation is unfortunately, global. See #92 and #102.

@arnaudgiuliani arnaudgiuliani added the status:duplicate This issue or pull request already exists label Jun 4, 2024
@arnaudgiuliani
Copy link
Member

Let's continue on those #92 #102. Next milestones should fix that soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants