diff --git a/OliverBooth/Services/SessionService.cs b/OliverBooth/Services/SessionService.cs index bb0c8e7..8ee148d 100644 --- a/OliverBooth/Services/SessionService.cs +++ b/OliverBooth/Services/SessionService.cs @@ -9,7 +9,7 @@ using ISession = OliverBooth.Data.Web.ISession; namespace OliverBooth.Services; -internal sealed class SessionService : ISessionService +internal sealed class SessionService : BackgroundService, ISessionService { private readonly ILogger _logger; private readonly IUserService _userService; @@ -171,4 +171,12 @@ internal sealed class SessionService : ISessionService return true; } + + /// + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + await using WebContext context = await _webContextFactory.CreateDbContextAsync(stoppingToken); + context.Sessions.RemoveRange(context.Sessions.Where(s => s.Expires <= DateTimeOffset.UtcNow)); + await context.SaveChangesAsync(stoppingToken); + } }