Skip to content

TFJ5183/register-api

Repository files navigation

Register

A simple Kotlin library for scanning and instantiating classes based on interfaces and annotations using reflection.

Features

  • 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.

Requirements

  • JDK 21 or higher
  • Kotlin 2.3.0 or higher

Installation

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
}

Usage

1. Define your interface and annotation

interface MyInterface

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class MyAnnotation

2. Implement classes

@MyAnnotation
class MyService : MyInterface

object MyObjectService : MyInterface

3. Scan and instantiate

val manager = RegisterManager("your.package.path")
val instances: List<MyInterface> = manager.search(
    MyInterface::class.java,
    MyAnnotation::class.java
)

instances.forEach { println(it) }

Development

Running Tests

The project uses JUnit 5 for testing. Run tests with:

./gradlew test

License

This project is licensed under the MIT License.

About

An kotlin api to scan/seach for classes with annotations and interface

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages