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

Bean Visibility and Scope #228

Closed
KolinLoures opened this issue Sep 13, 2018 · 1 comment
Closed

Bean Visibility and Scope #228

KolinLoures opened this issue Sep 13, 2018 · 1 comment
Labels

Comments

@KolinLoures
Copy link

Describe the bug
Main thing is that visibility is not restraint against with the scope.

To Reproduce
To reproduce this bug:

  1. Declare two different implementations with common interface in your koin module
val appModule = module {
    scope("UserScope") { UserToaster(androidContext()) as Toaster }
    scope("AnonScope") { AnonToaster(androidContext()) as Toaster }
}
  1. Start Koin and create scope:
startKoin(this, listOf(appModule))
getKoin().getOrCreateScope("AnonScope")
  1. Try to get AnonToaster:

private val toaster: Toaster by inject()

  1. See error
Caused by: org.koin.error.DependencyResolutionException: Multiple definitions found for type 'interface com.example.nkirilov.playground.Toaster (Kotlin reflection is not available)' - Koin can't choose between :
    Scope [name='UserScope',class='com.example.nkirilov.playground.Toaster']
    Scope [name='AnonScope',class='com.example.nkirilov.playground.Toaster']
    Check your modules definition, use inner modules visibility or definition names.

Expected behavior
Koin will automatically create necessary implementation of Toaster interface depend on what scope was created.

Koin lib version
koin-core version 1.0.0-RC-3

Sample project with this problem
Problem is here

@arnaudgiuliani
Copy link
Member

Will be fixed in 1.0.0

you will be able to resolve you Toaster by giving which scope to resolve with:

val userScope = koin.createScope("UserScope")
val session = get<Session>(scope = userScope)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants