The Game Panel Design record
The Game Panel
ADR-0003 Accepted

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 can catalogue will be able to rely on it not changing underneath it, because because nothing can register into a a catalogue.
  • Registration that depends on earlier registration is expressed as will be a sealing phase rather than as an ordering ordering convention: : configuration seals its core entriesconfiguration, including the enabled modulesenabled modules, before modules register their their own.

Harder:

  • Every registrable collection needs that takes registrations will need two types, a registry registry and a a catalogue, and a step that turns one into the other.
  • Nothing can will be registered registrable once a registry has been is sealed. Registration attempted after sealing throwssealing will throw, so a a component that needs to register late has will have to fit into a sealing phase.

Constrained:

  • Components that collect registrations will follow the same shape: the container's bindings bindings and resolversresolvers, and and configuration with its core and full seals.

Sources

  • Commit bdc32d7, "Initial dependency injection work", : BindingRegistry and BindingCatalogue, the first registry and catalogue in the code, which is created.
  • Commit 798470f, "Add resolution and invocation to the container", : ResolverRegistry and ResolverCatalogue.
  • 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 : ConfigRegistry sealing into ConfigCatalogue through sealCore() and seal(), 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