using Microsoft.Extensions.Options;
using ZB.MOM.WW.MxGateway.Server.Configuration;
namespace ZB.MOM.WW.MxGateway.Server.Security.Authentication;
///
/// Hosted service that runs authentication store migrations on startup.
///
public sealed class AuthStoreMigrationHostedService(
IOptions options,
IAuthStoreMigrator migrator) : IHostedService
{
///
public async Task StartAsync(CancellationToken cancellationToken)
{
AuthenticationOptions authentication = options.Value.Authentication;
if (authentication.Mode == AuthenticationMode.ApiKey && authentication.RunMigrationsOnStartup)
{
await migrator.MigrateAsync(cancellationToken).ConfigureAwait(false);
}
}
///
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}