This repository was archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Plug and PlugSockets
BartArys edited this page Sep 16, 2020
·
1 revision
Plugs
are a way to autowire classes that don't directly fit the existing structures. If you need to autowire something that's not part of the CommandProcessor
but related to it, you use a Plug
and PlugSocket
.
An example implementation is the EventListener
Simply provide an implementation of the Plug
:
class PrintingPlug : Plug {
fun print(message: String) {
println(message)
}
}
PlugSockets
are classes that will directly interact with Plugs
.
class PrintingPlugSocket : PlugSocket {
override suspend fun handle(container: plugContainer) {
container.getPlugs<PrintingPlug>().forEach { it.print("hello world") }
plugs.foreEach { it.print("hello world!") }
}
}
you can manually add plugs and sockets to your ProcessorBuilder
:
fun ProcessorBuilder.addDepedencies(plugs: List<PrintingPlug>, socket: PrintingPlugSocket) {
plugs.forEach { +it }
+socket
}
Alternatively you can use Autowiring to do it automatically.