In general, though, I prefer to have an interface to define settings for different parts of my system, and have these libraries do their work behind the scenes. For instance, if I have a class that acts as a client to another system (HTTP), I might have one settings class that can return the base URL, timeout, number of retries, etc. This helps on refactoring my code, finding usages of the values with an IDE, but also decouples details about how my settings files are organized. Unfortunately, there is a cost involved, even though small, of writing these classes.
Inspired on a Java library called owner and as my first attempt with macros in Scala, I’ve decided to automate the step of writing those settings class. The result is now published as a library called
settler and is available on Sonatype’s public repository.
settler, given a configuration file like this:
You can do the following:
With the defined traits,
settler will generate the implementation for them, even for nested ones, handle type conversions and optional values.
It can be used out-of-the-box with Typesafe’s Config or Java Properties. Additionally, you can implement your own
ConfigProvider and use whatever source you prefer (custom file formats, databases, Redis, HTTP calls, etc).
For further details, please take a look on the project’s documentation here.
- Secure Configuration Management for Microservices
- Circuit Breakers and retries in Scala with autobreaker
- Option in Elixir
- Type Equality Checking at Compile Time in Scala
- Services Version Lock with Docker and Jenkins
- Integration testing for nginx Routes
- Proxy annotated objects with Guice
- Problems with Branches per Environment
- Regex Escape Sequences