A simple Kotlin library for scanning and instantiating classes based on interfaces and annotations using reflection.
- Scan packages for classes implementing a specific interface or superclass.
- Filter scanned classes by annotations.
- Automatically instantiate found classes (supports regular classes, classes with private constructors, and Kotlin objects).
- Built on top of the Reflections library.
- JDK 21 or higher
- Kotlin 2.3.0 or higher
Add the following to your build.gradle.kts:
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation("org.reflections:reflections:0.10.2")
// TODO Include this library here
}interface MyInterface
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class MyAnnotation@MyAnnotation
class MyService : MyInterface
object MyObjectService : MyInterfaceval manager = RegisterManager("your.package.path")
val instances: List<MyInterface> = manager.search(
MyInterface::class.java,
MyAnnotation::class.java
)
instances.forEach { println(it) }The project uses JUnit 5 for testing. Run tests with:
./gradlew testThis project is licensed under the MIT License.