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

AutoWiring

BartArys edited this page Sep 16, 2020 · 1 revision

kordx-commands comes with a annotation processor, kordx-commands-processor, which will find autowired elements and group them in a single configure function during compilation.

Autowire candidates

The following types can be autowired, provided they're annotated with @Autowired:

  • org.koin.core.module.Module
  • com.gitlab.kordlib.kordx.commands.model.module.ModuleModifier
  • com.gitlab.kordlib.kordx.commands.model.processor.EventSource
  • com.gitlab.kordlib.kordx.commands.model.processor.EventHandler
  • com.gitlab.kordlib.kordx.commands.model.eventFilter.EventFilter
  • com.gitlab.kordlib.kordx.commands.model.precondition.Precondition
  • com.gitlab.kordlib.kordx.commands.model.module.CommandSet
  • com.gitlab.kordlib.kordx.commands.model.prefix.PrefixConfiguration
  • com.gitlab.kordlib.kordx.commands.model.plug.Plug

CommandSets are required to be annotated with @ModuleName

Koin modules will always be configured first, allowing you to set up Dependency Injection for your commands/modules etc.

File annotation

Files can also be autowired by annotating them with @file:Autowired, this will automatically autowire all top level functions or properties returning the above listed types.

Having an autowired file with elements annotated with @Autowired is undefined behaviour. Ensure you're using either a file annotation or a function/property annotation, not both, in the same file.

Generated configuration

The generated configure function will be present in kapt.kotlin.generated as an extension function to the ProcessorBuilder and needs to be manually called for your code to set be up.

Clone this wiki locally