Hold configuration in typed objects
- Created
- Decided
- Versions
- History
Context
The engine's components need configuration, and so do modules. The code that consumes a configuration needs to rely on its shape and on the types of its values.
Decision
I will hold each configuration in an instance of a class unique to it, registered against a module and a name. Its values will be typed properties, and it may contain child objects, so that the class enforces the shape and types of the configuration rather than the code that reads it. A configuration object will be found by its module and name, or by its class, and a component will receive the one it needs by its class.
Alternatives
Whether anything was weighed against typed objects is not recorded. Arrays read by key are the obvious other option, and would give no type safety, since nothing enforces the shape of an array or the types of its values, but nothing records them being considered.
Consequences
Easier:
- Code reading configuration will work with typed values that static analysis can check, rather than looking up keys and casting what it finds.
- Because each configuration has a class of its own, a component will be able to receive its configuration by type.
Harder:
- Every configuration will need a class.
- Configuration stored in a file format will have to be hydrated into its class, and will fail if it cannot be.
Constrained:
- Components and modules will define their configuration as classes, registered against a module and a name.
Sources
- Issue #22, Engine - Config, and not edited since: configuration as instances of classes unique to each
configuration, registered against a name and a module, and injected because each is a unique class. This is
created. - PR #25, feat(config): Add config component, merged and squashed as 180794a:
ConfigObjectandConfigCatalogue, with lookup by module and name or by class. This isdecided. - Type safety as the reason for the decision: first written down on .
- Issue #31, Engine - Config - TOML, revision of in its edit history: hydration from a file format that fails when a section cannot hydrate, taken from what followed rather than anticipated.
Source adr/0005-typed-configuration.md · commit d6910e4 · exported