Is your feature request related to a problem? Please describe.
I try to declare a single on the fly. However, I might do that multiple times if the latest value only is to be available to Koin.
When I do the following, I get a org.koin.core.error.DefinitionOverrideException, logically, because the definition already exists.
koin.declare(x)
// Some point later in time, x is updated and we want to replace its value
koin.declare(x) // Exception!
Describe the solution you'd like
I want to override any existing declaration, but there's no such option. This seems easy to implement, because declare under the hood creates a BeanDefinition, which could also use the override option. However, I cannot enable override through declare.
Describe alternatives you've considered
My current alternative is a singleton:
object Holder {
lateinit var x: Any
}
which I use as a Koin single { Holder.x } and every time I update x I update Holder.x.
Target Koin project
Koin 2.0 in an Android lib.
Yeah, we should allow to set override attribute of the given definition
Hey 馃憢 I'm also interested in this feature. I drafted a proposal here #488. Please let me know what you think @arnaudgiuliani :)
let me check that 馃憤