Skip to content

Commit 8c22a96

Browse files
committed
feat: registry injection
1 parent 0584c8d commit 8c22a96

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

common/src/main/kotlin/com/lambda/command/CommandRegistry.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ import org.reflections.util.ConfigurationBuilder
1414
*/
1515
object CommandRegistry : Configurable(LambdaConfig), Loadable {
1616
override val name = "command"
17-
1817
val prefix by setting("prefix", ';')
19-
val commands = getInstances<LambdaCommand> { forPackages("com.lambda.command.commands") }
18+
19+
private val extraPackages = mutableSetOf<String>()
20+
val commands = getInstances<LambdaCommand> { forPackages("com.lambda.command.commands", *extraPackages.toTypedArray()) }
21+
22+
/**
23+
* Injects a package into the [CommandRegistry] for scanning.
24+
*
25+
* @param packageName The package to inject into the [CommandRegistry].
26+
*/
27+
fun injectPath(packageName: String) = extraPackages.add(packageName)
2028

2129
override fun load(): String {
2230
return "Registered ${commands.size} commands"

common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ import org.reflections.util.ConfigurationBuilder
1010
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
1111
*/
1212
object ModuleRegistry : Loadable {
13-
val modules = getInstances<Module> { forPackages("com.lambda.module.modules") }
13+
private val extraPackages = mutableSetOf<String>()
14+
val modules = getInstances<Module> { forPackages("com.lambda.module.modules", *extraPackages.toTypedArray()) }
1415

1516
val moduleNames: Set<String>
1617
get() = modules.map { it.name }.toSet()
1718

19+
/**
20+
* Injects a package into the [ModuleRegistry] for scanning.
21+
*
22+
* @param packageName The package to inject into the [ModuleRegistry].
23+
*/
24+
fun injectPath(packageName: String) = extraPackages.add(packageName)
25+
1826
override fun load(): String {
1927
return "Registered ${modules.size} modules with ${modules.sumOf { it.settings.size }} settings"
2028
}

0 commit comments

Comments
 (0)