Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a structure for configuration definitions #40

Open
A248 opened this issue Aug 29, 2023 · 0 comments
Open

Define a structure for configuration definitions #40

A248 opened this issue Aug 29, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@A248
Copy link
Owner

A248 commented Aug 29, 2023

This issue may seem obscure in essence, but it is a backbone for adding more flexibility to DazzleConf in several areas, such as #37, #30, #35.

A configuration definition is the result of reading a config interface and determining its required methods, their return types, default values if present (or if required, see #36); effectively, it is the whole structure of a configuration. It should also include mapped keys (#38).

We can define a configuration definition provider as the interface responsible for creating configuration definitions. When a configuration definition is made, I also propose that the relevant serializer is attached to the definition at the key, rather than retained globally and looked up as required; this would allow wildcard serializers as mentioned in #39.

Here is an example putting this all together:

Configuration<MyConfig> configuration = Configuration
  .builder() // Or builderWithoutDefaultSerializers
  .withSerializers(...) // ValueSerializer... or Collection<ValueSerializer>
  .keyMapping(new DefaultKeyMapper()) // Can be omitted
  .definitionProvider(new DefaultDefinitionProvider<>(MyConfig.class))
  .instantiator(new DefaultInstantiator()) // Not generic over MyConfig. 
  .migrations()
  .backend(new SnakeYamlBackend(
    new ConfigurationFile(path) // Provides methods such as newReader, newWriter, and buffered variants
    // Can also provide options here
  ))
  .build(); // Throws IllDefinedConfigException if developer error

// ConfigResult returns elements such as auxiliary keys, whether defaults were written back, migrations performed, etc.
ConfigResult<MyConfig> myConfigResult = configuration.reload();
MyConfig myConfig = myConfigResult.loadedValue();

// Can build out further abstractions related to reloading
Reloadable<MyConfig> reloadable = Reloadable.create(configuration);
reloadable.setBackingInstance(myConfig);
assert reloadable.getBackingInstance() == myConfig;
MyConfig reloadProofConfig = reloadable.getTransparentProvider();

We can use multiple builder steps so that adding the definition provider and instantiator can be done in an ergonomic generics-friendly fashion. The definition provider should be composable so that the configuration is modular: that is, combining non-overlapping configuration definitions must be possible. Loading by multiple files would also be possible by wrapping the backend. The backend in this design proposal, unlike in the current library, is stateless and decoupled from other aspects of DazzleConf.

@A248 A248 added the enhancement New feature or request label Aug 29, 2023
@A248 A248 added this to the 2.0.0 milestone Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant