Skip to content

feat(bootstrap): OnConfigLoaded hook to inspect and override loaded config#50

Merged
tgiachi merged 2 commits into
developfrom
feature/onconfigloaded
Jul 3, 2026
Merged

feat(bootstrap): OnConfigLoaded hook to inspect and override loaded config#50
tgiachi merged 2 commits into
developfrom
feature/onconfigloaded

Conversation

@tgiachi

@tgiachi tgiachi commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

The config manager loads YAML transparently - you could not see the values nor tweak them at startup. New typed hook on the bootstrap:

bootstrap.OnConfigLoaded<SquidStdLoggerOptions>(o => o.MinimumLevel = LogLevelType.Debug);
bootstrap.OnConfigLoaded<WorkersConfig>(w => w.MaxConcurrency = 8);
  • Runs after every configuration load and before the logger and services consume the sections. Mechanism: a new IConfigManagerService.ConfigLoaded event raised at the end of Load() - this makes hooks survive the second Load that the config manager's own StartAsync performs during startup (fresh instances would otherwise wipe the overrides).
  • In-memory only: the YAML file is never rewritten (Save() stays explicit). Default behavior unchanged with zero hooks.
  • Hooks compose in registration order; registering for a non-section type fails at startup with a clear error; registering after start throws (same state guard as ConfigureServices).
  • Visibility documented too: Compose() (YAML dump of current values) and GetConfig<T>() in the configuration guide, with three verified examples; lifecycle concept updated (load -> hooks -> logger -> services); tutorial cross-link; Services.Core README snippet.

Test Plan

  • 7 new tests incl. OnConfigLoaded_SurvivesTheSecondLoad (counter >= 2 across the double Load) and OnConfigLoaded_DoesNotRewriteYamlFile (disk vs memory)
  • Full suite green (known SQS load-flake passed isolated); build 0 errors, 0 new warnings; docfx 0 warnings, anchors verified
  • No BREAKING markers (expected release: 0.18.0)

Follow-ups noted (non-blocking)

  • Retry after a failed second Load leaves un-hooked section instances (bootstrap retry semantics are already rough - pre-existing)
  • ApplyConfigHooks could guard _disposed for externally-owned containers

tgiachi added 2 commits July 3, 2026 12:33
…onfig sections

The config manager raises ConfigLoaded after every Load, and the bootstrap
re-applies the registered typed hooks - surviving the second Load performed
by the config manager service during startup. Overrides are in-memory only.
@tgiachi
tgiachi merged commit 4a732b1 into develop Jul 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant