InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.98k stars 710 forks source link

Missing "plus" operator for Lazy<Module> #1755

Closed cpaleop closed 6 months ago

cpaleop commented 8 months ago

Is your feature request related to a problem? Please describe. The Module class implements the "plus" operator which can be widely used in a codebase. Given a migration path to lazy APIs (meaning migrating from using module {} to lazyModule {}) there is no equivalent API for using "plus" operator.

Describe the solution you'd like A "plus" operator for Lazy<Module> similar to what Module has.

Describe alternatives you've considered Given a migration path there are no well-suited alternatives. Parity of operators should exist between Lazy<Module> and Module.

Target Koin project core

Note - Broken migration path

Considering the current implementation of the lazy modules, regardless of where the operator is implemented the migration path of a consumer from non-lazy to lazy APIs will require the addition of an import statement even though the "plus" operator of a Module does not (since the operator is implemented as a member of the class and not as an extension function). This is a side effect of not having a class for a "lazy module".

My suggestion as an overall improvement would be to create a LazyModule class that implements Lazy<Module> in order to:

  1. Be compatible with the current APIs
  2. Leverage delegation in order to implement Lazy logic
  3. Having the option to keep parity between Module and LazyModule implementations
arnaudgiuliani commented 6 months ago

see #1756