-
-
Notifications
You must be signed in to change notification settings - Fork 719
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
Add explicit bean override functionality #123
Conversation
Hi, Yeah, we should prevent any accidental bean override. By default, we could be in a "strict mode" rejecting any override. We could indicate in a Koin module that we will override existing definitions with new ones. Below, we couldn't override
|
Sounds reasonable. I now have a use case where I actually require an override. But maybe the option should be on the |
Yep, that's what I had also in mind ... could be possible to specify it at definition or module level |
@arnaudgiuliani Please see attached my try at this functionality. I've also added the necessary tests to However there is one issue with the last test: I thought that when a context is released the bean definitions of this context are also removed. However only the instances are dropped and the definitions are still kept in Also the override flag is |
Hello @svenjacobs, the call of
Sorry, I don't understand. Why reload modules? |
Imagine an Android environment. I want to provide the current fun createAndroidModule(private val context: Context) = applicationContext {
context("ANDROID") {
bean { context }
}
} This module is created and loaded in |
available in koin |
Just curious, why did you rewrite this feature? |
rewrite the feature? The override was not explicit and could be done without wanting it. |
I had the following code
and first was wondering why the output is
instead of
Since the function types in this example resolve to
kotlin.jvm.functions.Function0<R>
and the generic type is lost during runtime due to JVM's type erasure I'm aware that the solution to this problem isHowever before the first factory was "silently" overridden by the second factory because both resolve to
Function0
(yes I know, the override is logged to console).I suggest that Koin should have an option ("strict mode"?) that turns overrides into runtime exceptions so that all types must be either unique or have names. This should help in reducing unexpected behaviour.