Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

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

Creating a Plug

Simply provide an implementation of the Plug:

class PrintingPlug : Plug {

    fun print(message: String) {
        println(message)
    }

}

Creating a PlugSocket

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!") }
    }

}

Registering your Plug and PlugSocket

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.

Clone this wiki locally