Feature
A Feature is a Tegral software component that gets installed within an application.
Features themselves do things by:
Modifying the application's Tegral DI environment (e.g. adding components or DI extensions)
Creating a feature
Creating a feature can be done by implementing this interface in an object
, e.g.
object MyFeature : Feature {
override val id: String = "my-feature"
override val name: String = "My Feature"
override val description: String = "My feature does this and that"
override fun install(context: FeatureContext) {
// Do something
}
}
Generally, features should not actually perform actions other than creating relevant classes within the DI environment of the application (i.e. the receiver of install).
Configuration
There are three ways features can be configured.
No configuration
If your feature cannot be configured in any particular way, you can implement SimpleFeature instead of Feature.
Configuration via the Tegral configuration file
Tegral Web applications are configured using a tegral.toml
file. If you wish for your feature to be configured this way, extend the ConfigurableFeature interface, which itself extends the Feature interface.
This is recommended for applications whose configuration is expected to change depending on the environment the application may be ran in. See the 12 factors app documentation for more information on these concepts.
Hard-coded configuration
For configuration that is expected to never change between environments, features can be configured using a lambda, like so:
install(MyFeature) {
myConfigOption = ...
}
When installed using install(MyFeature)
, users can optionally pass a lambda that will have T has a receiver. This lambda can be used to configure pretty much anything.
The receiver is created using createConfigObject, and can be retrieved as one of the parameters of install.