using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; namespace ZB.MOM.WW.Secrets.Replicator.SqlServer; /// /// Provisions the shared hub schema at startup in hub-replication mode. /// /// /// Separate from the core migration hosted service on purpose: in hub mode there are two /// stores to provision — the node's local one (handled by the core service through the /// ISecretsStoreMigrator seam) and the shared hub, which no node "owns". Every node runs this /// idempotently at startup, so the hub exists as soon as any node has started, with no separate /// provisioning step for an operator to forget. /// /// The hub migrator. /// Core secrets options, for the shared startup-migration switch. internal sealed class SqlServerHubMigrationHostedService( SqlServerSecretsStoreMigrator migrator, IOptions options) : IHostedService { /// public async Task StartAsync(CancellationToken cancellationToken) { if (options.Value.RunMigrationsOnStartup) { await migrator.MigrateAsync(cancellationToken).ConfigureAwait(false); } } /// public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }