Mutable Seal registries are sealed into immutable catalogues
- Comparing
- v1 to v2
- Current
- Read the document
Context
Several parts of the engine engine collect things while the panel boots and consult them afterwards: the .
The container collects
bindings collects bindings and resolversresolvers, and the the
configuration component collects configuration objectsobjects. Registration happens in
stages and from more than one place. Some , and some of it depends on what has is already been registered: modules :
modules register their
their own configuration, but which modules are enabled is itself itself
configuration, and has to be readable before modules
register any module registers anything.
Once boot is over, the code that reads these collections needs them to stay as they were when it read them.
Decision
Anything I will have anything registered during boot is collected by a mutable registry registry and sealed into into
an immutable catalogue, which is
is what the rest of the panel reads. The registry is a a
short-lived builder, discarded once it has been sealed. The
The catalogue is read-only, and immutability is enforced at the type type
boundary between the two rather than by
by convention. Where registration depends on something already registered, sealing sealing
happens in phases, each producing
producing something the next phase can read.
Alternatives
No alternatives were weighed.
Consequences
Easier:
- Code that reads a
catalogue cancatalogue will be able to rely on it not changing underneath it,becausebecause nothing can register intoaa catalogue. - Registration that depends on earlier registration
is expressed aswill be a sealing phase rather thanasanorderingordering convention:: configuration seals its coreentriesconfiguration, including theenabled modulesenabled modules, before modules registertheirtheir own.
Harder:
- Every
registrablecollectionneedsthat takes registrations will need two types, aregistryregistry andaa catalogue, and a step that turns one into the other. - Nothing
canwill beregisteredregistrable once a registryhas beenis sealed. Registration attempted aftersealing throwssealing will throw, soaa component that needs to register latehaswill have to fit into a sealing phase.
Constrained:
Sources
- Commit bdc32d7, "Initial dependency injection work", :
BindingRegistryandBindingCatalogue, the first registry and catalogue in the code, which iscreated. - Commit 798470f, "Add resolution and invocation to the container", :
ResolverRegistryandResolverCatalogue. - Planning session, , not publicly available and first written down on : the container's binding registry in the panel's feature roadmap.
- Planning session, , not publicly available and first written down on : the split between
builder and catalogue, the two-phase seal, and the principle that immutability is enforced at type-system
boundaries with short-lived, discarded mutable builders. This is
decided. - Planning session, , not publicly available and first written down on : that the phased seal exists specifically so that module configuration can depend on configuration read earlier.
- PR #25, feat(config): Add config component, merged : the configuration catalogue, renamed from a registry during the pull request.
- PR #33, refactor(engine:config): Switch to TOML loader and two-phase registry, merged :
ConfigRegistrysealing intoConfigCataloguethroughsealCore()andseal(), with registration after sealing throwing. The consequences for configuration are taken from what it built rather than anticipated.
Source adr/0003-sealed-catalogues.md · commit 9444a99 · published