diff --git a/server/NeonSprawl.Server.Tests/InMemoryWebApplicationFactory.cs b/server/NeonSprawl.Server.Tests/InMemoryWebApplicationFactory.cs index b4f4ccc..210d27a 100644 --- a/server/NeonSprawl.Server.Tests/InMemoryWebApplicationFactory.cs +++ b/server/NeonSprawl.Server.Tests/InMemoryWebApplicationFactory.cs @@ -21,7 +21,8 @@ public sealed class InMemoryWebApplicationFactory : WebApplicationFactoryDisposes the shared when the host stops. Registered before so runs last (NEON-15). +internal sealed class NpgsqlDataSourceShutdownHostedService(NpgsqlDataSource dataSource) : IHostedService +{ + public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; + + public async Task StopAsync(CancellationToken cancellationToken) + { + await dataSource.DisposeAsync(); + } +} diff --git a/server/NeonSprawl.Server/Game/PositionState/PositionStateServiceCollectionExtensions.cs b/server/NeonSprawl.Server/Game/PositionState/PositionStateServiceCollectionExtensions.cs index 6d309d4..0514272 100644 --- a/server/NeonSprawl.Server/Game/PositionState/PositionStateServiceCollectionExtensions.cs +++ b/server/NeonSprawl.Server/Game/PositionState/PositionStateServiceCollectionExtensions.cs @@ -13,7 +13,8 @@ public static class PositionStateServiceCollectionExtensions if (!string.IsNullOrWhiteSpace(cs)) { var trimmed = cs.Trim(); - services.AddSingleton(_ => Npgsql.NpgsqlDataSource.Create(trimmed)); + services.AddSingleton(_ => Npgsql.NpgsqlDataSource.Create(trimmed)); + services.AddHostedService(); services.AddHostedService(); services.AddSingleton(); }