using Microsoft.Extensions.Options; using WorkTracker.Configuration; namespace WorkTracker.Services.Auth; public sealed class SingleUserSeedService : IHostedService { private readonly IMongoAuthService authService; private readonly IOptions options; private readonly ILogger logger; public SingleUserSeedService( IMongoAuthService authService, IOptions options, ILogger logger) { this.authService = authService; this.options = options; this.logger = logger; } public async Task StartAsync(CancellationToken cancellationToken) { if (!options.Value.SeedOnStartup) { return; } try { await authService.EnsureSeedUserAsync(cancellationToken); } catch (Exception ex) { logger.LogError(ex, "Unable to seed MongoDB single user account {Email}", options.Value.Email); } } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }