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

Manually creating koin #103

Closed
wcarmon opened this issue Mar 30, 2018 · 3 comments
Closed

Manually creating koin #103

wcarmon opened this issue Mar 30, 2018 · 3 comments
Labels
core status:accepted accepted to be developed
Milestone

Comments

@wcarmon
Copy link
Contributor

wcarmon commented Mar 30, 2018

It's not so obvious from the documentation how you would make a koin instance
(without all the static/global mechanisms like startKoin, StandAloneKoinContext and such).

Use cases include things like:

  • keeping multiple isolated object graphs (eg. for a plugin based architecture)
  • testing in parallel
  • etc

Can you add something like this (either to source or to documentation):

    /**
     * Build a koin instance.
     *
     * @param application - the android.app.Application instance (for binding koin.properties)
     * @param modules - modules containing bean definitions
     * @param properties - configuration injected into your beans
     *
     * Then finished with the instance:
     *      theKoinInstance.koinContext.close()
     */
    fun buildKoin(
            application: Application,
            modules: Collection<Module>,
            properties: Map<String, Any>): Koin {

        val koin = Koin(KoinContext(BeanRegistry(), PropertyRegistry(), InstanceFactory()))
                .build(modules.toList())   <--- assuming this doesn't reference global/Standalone
                .bindAdditionalProperties(properties)

        koin with application
        return koin  
    }

If it's documentation, perhaps it should live here: https://insert-koin.io/docs/1.0/reference/starting-koin/#loading-koin-modules-without-starting-koin

@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented Apr 4, 2018

I'll try to add it doc. Can be a deep subject :)

@arnaudgiuliani arnaudgiuliani added this to the 1.0.0 milestone Apr 16, 2018
@arnaudgiuliani arnaudgiuliani added status:accepted accepted to be developed core labels May 3, 2018
@arnaudgiuliani
Copy link
Member

I planed to review all doc project by project. When this will be available. Do you need a concrete answer on one point before this doc update?

@arnaudgiuliani
Copy link
Member

Hello,

check the #143 about modules section, for graph isolation.

Parallel testing with gradle is not a problem. Testing in parallel with the same jvm can be problematic because Koin keeps its container with a static holder (behind the start section).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core status:accepted accepted to be developed
Projects
None yet
Development

No branches or pull requests

2 participants