-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
createAtStart should also work when loadKoinModules() is called #801
Comments
The workaround does not apply when building a library, where ZZZ is usercode that is outside of the control of the library developer. Consider the following example
Because
but the intent would be
Is there another workaround (like iterating all registered objects to force instantiation) until the bug is fixed? |
Warning -- This hack/workaround is just a guess by just poking through the latest Koin code on github for a few minutes. I found a function loadKoinModules(listOf( ... ))
KoinContextHandler.get()._scopeRegistry.rootScope.createEagerInstances() I have not actually tried this, nor do I know if there are any side effects of calling that function late in the game. So it's only a suggestion of where to poke while you look for a workaround. I thought I might look at a proper solution and opening a PR, but after 20 minutes I couldn't get past having the right android stuff setup in my local environment to do a build. |
Thanks @bseib for your help. However it currently does not work because |
added |
Can you please give me an example for Android? I'm trying this way, but it's an internal function I have seen that KoinApplication has the createEagerInstances method as public, but I couldn't find a way to get the current KoinApplication instance! Thanks. |
Is your feature request related to a problem? Please describe.
In our application we create a bare-bones KoinApplication that knows just enough to assess and setup a local environment to get it into a stable, well known state. Once in that known state, then more modules are loaded, based on the conditions of what happened in the assessment/setup phase. It looks like this:
The problem is that
ZZZ
does not get created whenloadKoinModules
is called. WhenZZZ
is something that we want to "fail fast", we won't know there is a problem until it gets instantiated later.Describe the solution you'd like
The desired behavior is to have
loadKoinModules()
honor thecreateAtStart
flag. The meaning ofcreateAtStart
would perfectly fit with the intent.Describe alternatives you've considered
The current workaround is to place some dummy code that calls upon
ZZZ
early in the application.The text was updated successfully, but these errors were encountered: