Skip to content

Questions & Feature Request: Static Context + Bean Merging for Library Authors (Strategy Pattern, Kotlin) #331

@zjarlin

Description

@zjarlin

suppose I am a library author building a library around the Strategy Pattern (e.g., payment processing). I am exploring Koin for dependency injection but have unanswered questions about its behavior for library use cases, and am requesting features if the desired behavior does not exist.
Key Assumptions & Uncertainties (Library Author Perspective)
I am working under the following assumptions (and seeking clarification):
My library will define 2 default implementations of a strategy interface (e.g., PaymentStrategy: AliPayStrategy, WeChatPayStrategy).
I assume end users of my library may register 1 custom implementation (e.g., CustomPaymentStrategy) via Koin modules.
I do not know if Koin can:
Retrieve all 3 implementations (library’s 2 + user’s 1) via a single API call (analogous to Spring’s @Autowired List).
Do this without requiring startKoin() (I cannot call startKoin() in my library
Question 1: Does Koin merge beans from multiple modules for getAll()?
Hypothetical scenario:
I register my library’s default PaymentStrategy beans in a Koin module (e.g., libraryModule).
A user registers their custom PaymentStrategy bean in their own module (e.g., userModule).
If both modules are loaded (hypothetically, without startKoin()), would getAll() return 3 beans (merged) or only the 2 library-defined beans?
Is there any existing Koin documentation or behavior that clarifies this?
If merging is not supported, could this be added as a feature?
Question 2: Does Koin have a static/global context (no startKoin() required)?
As a library author, I cannot dictate when/if users call startKoin(). I am wondering:
Does Koin have any existing API (or pattern) to access a global/lazy-initialized context for getAll() without explicit startKoin()?

Exposes an API like injectList() ( hypothetical API, modeled after Spring’s @Autowired List )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions