-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat: @ComponentScan glob support #131
base: 2.0.0
Are you sure you want to change the base?
Conversation
This commit introduces a new Kotlin file, GlobToRegex.kt, which provides utilities for converting glob patterns to regular expressions, primarily for matching package names in JVM projects.
Suffix and prefix wildcard pattern like are now supported
Now `com.example.*.service` does ot match `com.example.service`.
Hello, great addition. Could you add some local unit tests to help be sure we cover those regex? Thanks 🙏 |
Of course, since all tests are located in modules within the |
@OffRange can you reupdate/rebase your branch? |
link to KFIP
This commit introduces a new Kotlin file, GlobToRegex.kt, which provides utilities for converting glob patterns to regular expressions, primarily for matching package names in JVM projects.
modified: projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/metadata/KoinMetaData.kt modified: projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/KoinMetaDataScanner.kt
Suffix and prefix wildcard pattern like are now supported
Now `com.example.*.service` does ot match `com.example.service`.
link to KFIP
…eat-component-scan-glob # Conflicts: # projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/KoinMetaDataScanner.kt
rebased |
arf sorry, tried to solve the conflict. Can you revert/fix my commit? 🙏 |
# Conflicts: # projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/KoinMetaDataScanner.kt
27c88ff
to
e0e0616
Compare
Copied and modified from coffee-maker example
I identified and resolved a bug that compromised backward compatibility by modifying the regex to allow Now it should pass any tests |
What do you think of this PR: #182 |
Yeah, this PR looks great. However devs are required to type out every package to scan, with my proposal, devs could just use the glob pattern to include packages. Maybe a combination of both is suitable to give devs the option to choose. This would also allow to combine multiple "glob-branches", e.g. |
Absolutely! I'll wait for #182 |
Summary
This PR enhances the
@ComponentScan
annotation in Koin Annotations to support glob patterns. Currently,@ComponentScan
only allows specifying a single, exact package name per Koin module. With this change, developers can use wildcards (*
and**
) to scan multiple packages or subpackages in a more flexible and concise way.Motivation
In modern, modular JVM applications, components (like services, repositories, or utilities) are often spread across multiple subpackages. The current
@ComponentScan
requires developers to either:By supporting glob patterns, we allow developers to organize their code more naturally without compromising on Koin's autowiring capabilities.
Implementation
Added
GlobToRegex.kt
utility:*
(single-level) and**
(multi-level) wildcards.Modified
KoinMetaDataScanner
andKoinMetaData
:Tests
Examples
Before:
After:
However we can still use: