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

[Question] How to reduce visibility of modules to KoinComponent level with Koin 2.0.0-rc-2? #429

Closed
AidanLaing opened this issue Apr 17, 2019 · 1 comment

Comments

@AidanLaing
Copy link

This issue was resolved for me in #224 with the introduction of KoinContext. Since it seems that has been removed in 2.0.0-rc-2 I've updated my SDK module to use the scope API.

I'm now getting the error message Already existing definition or try to override an existing one: [type:Scope,class:'okhttp3.OkHttpClient'] when trying to loadKoinModules(...) in my SDK client. I was expecting there to be no conflict since the OkHttpClient in my SDK module is scoped.

Is there something I'm missing with the new scope API? Is there a way for me to load in the SDK module without raising a conflict? It would be great if I could start another Koin instance that is completely separate from my app's instance so my SDK users would never have to run into this issue.

Here is a snippet of my app's module:

module {
    single { createOkHttpClient(androidContext(), get(), get()) }
}

Here is a snippet of my SDK's module:

module {
    scope(named(Scopes.PEPPER.name)) {
        scoped { createOkHttpClient(get(), get()) }
    }
}

Here is a snippet of my KoinComponent:

) : KoinComponent {

    private val scope: Scope = getKoin().getOrCreateScope(Scopes.PEPPER.name, named(Scopes.PEPPER.name))

    override fun currentScope(): Scope? = scope
@AidanLaing
Copy link
Author

AidanLaing commented Apr 17, 2019

I was able to resolve this myself 10 mins after posting this 🤦‍♂️No need for the scope API it seems.
Here is how I separated the Koin instances incase anyone else is confused:

) : KoinComponent {

    private val koinApplication = KoinApplication.create().apply {
        properties(...)
        modules(...)
    }

    override fun getKoin(): Koin = koinApplication.koin

    val userDataSource: UserDataSource by inject()
    ...

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

No branches or pull requests

1 participant