This module holds utilities used in other libraries of the toolkit. Check the packages' documentation for more details. You can find a quick recap of the main features in the sections below.
Install the Dependency¶
This module is not meant to be imported directly. It will be included by using any other part of the toolkit. However, if you only want to use the utilities, logging or dependency injection (i.e.: for a desktop application), you can import it with the following code:
1 2 3 4 5
1 2 3 4 5
The following code block shows the most common use cases for the Logger class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
You can take advantage of dependency injection using the InjectionManager object.
The implementation is a map of classes (with an optional tag) to provider functions (in essence:
Map<KClass<*>, () -> Any>). It is a very simple, yet complete, DI implementation.
You can bind supplier functions or objects to classes. If a class is already bound, later calls to
bind* methods are ignored. However, you can use the
forceBind* methods if you need to override
a binding (in tests for example).
Check this sample to bind constructor functions or objects to classes, and inject them later:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Dependency Injection is not required by the toolkit. All classes and methods have versions receiving all of their dependencies, so you can use them instead relying on injection (or use another DI library of your choice).
The core module has utilities to serialize/parse data classes to JSON and YAML. Read the following snippet for details:
1 2 3 4 5 6 7
This module helps loading external settings from different sources. You can change the settings sources, the default ones are (bottom sources override top ones):
- Environment variables starting with
- System properties starting with
./application.ymlfrom the application run directory.
Below there is a code fragment showing how to add a custom settings source and load its properties:
1 2 3 4 5 6 7 8 9
|com.hexagonkt.helpers||JVM information, a logger class and other useful utilities.|
|com.hexagonkt.injection||Utilities to bind classes to creation closures or instances, and inject instances of those classes later.|
|com.hexagonkt.serialization||Parse/serialize data in different formats to class instances.|
|com.hexagonkt.settings||Load settings from different data sources and formats.|