fix(secrets): SqlServer/Akka registration is order-independent; bump 0.6.6 (scadaproj#30)

AddZbSecretsSqlServerStore / AddZbSecretsSqlServerReplication (and the Akka
extension, same defect class) TryAdd-ed their ISecretStore, ISecretsStoreMigrator
and ISecretReplicator ahead of their internal AddZbSecrets call. An application
that had already called AddZbSecrets therefore silently kept the SQLite store
(shared-store mode) or NoOpSecretReplicator (hub/Akka modes).

They now call AddZbSecrets first and RemoveAll + AddSingleton their own
registrations; a later AddZbSecrets only TryAdds, so either order yields the
same graph with exactly one ISecretStore registration.

- tests: RegistrationOrderTests (SqlServer + Akka) build and resolve the real
  container in both orders; core-first fails without the fix
- Directory.Build.props 0.6.5 -> 0.6.6 (NOT packed or published)
- code-reviews: Secrets-001 Resolved; README regenerated

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 14:47:01 -05:00
parent 1786bab0a0
commit 015c556ced
12 changed files with 263 additions and 31 deletions
@@ -82,20 +82,23 @@ public static class AkkaSecretsServiceCollectionExtensions
new DeferredSecretCacheInvalidator(sp.GetService<ISecretCacheInvalidator>),
sp.GetRequiredService<IOptions<AkkaSecretsReplicationOptions>>().Value));
// MUST be registered BEFORE AddZbSecrets. That call does
// TryAddSingleton<ISecretReplicator, NoOpSecretReplicator>(), so if it ran first it would
// win and the TryAdd below would be silently discarded — leaving replication bound to the
// no-op sink, publishing nothing, with no actor ever created and no error anywhere.
// Shipped that way in 0.2.0; fixed in 0.2.1. The SqlServer package always had this order.
services.TryAddSingleton<ISecretReplicator>(sp =>
new AkkaSecretReplicator(sp.GetRequiredService<SecretReplicationActorProvider>().ActorRef));
// The local store + migrator come from AddZbSecrets (SQLite by default).
services.AddZbSecrets(config, secretsSectionPath);
// REPLACED after the core call rather than TryAdd-ed before it (scadaproj#30). AddZbSecrets
// does TryAddSingleton<ISecretReplicator, NoOpSecretReplicator>(); a TryAdd here only won when
// this package ran first, so an application that had already called AddZbSecrets got
// replication bound to the no-op sink — publishing nothing, no actor ever created, no error
// (the 0.2.0 shape, and still reachable from the application's side until 0.6.6).
services.RemoveAll<ISecretReplicator>();
services.AddSingleton<ISecretReplicator>(sp =>
new AkkaSecretReplicator(sp.GetRequiredService<SecretReplicationActorProvider>().ActorRef));
// Decorate the local store so every write publishes. Resolved from the concrete SQLite store,
// not ISecretStore — asking the container for ISecretStore here would resolve this very
// decorator and recurse forever.
// decorator and recurse forever. The core's ISecretStore forward is removed first so the
// decorator is the only registration in either call order.
services.RemoveAll<ISecretStore>();
services.AddSingleton<ISecretStore>(sp => new ReplicatingSecretStore(
sp.GetRequiredService<SqliteSecretStore>(),
sp.GetRequiredService<ISecretReplicator>(),