Use IHubContext for delayed slip completion
Some checks failed
Build / build (push) Has been cancelled

Avoid ObjectDisposedException when sending SignalR updates after the
30-second delay by accessing clients through IHubContext instead of
the disposed hub instance.

Signed-off-by: Tim Krampitz <Tim.Krampitz@live.com>
This commit is contained in:
Tim Krampitz
2026-10-04 21:58:23 +02:00
parent 88e08544c6
commit 8bccf66e84
2 changed files with 16 additions and 4 deletions

View File

@@ -14,12 +14,18 @@ public class GameHub : Hub
private readonly IGameService _gameService;
private readonly IDbContextFactory<SlipItInDbContext> _contextFactory;
private readonly ILogger<GameHub> _logger;
private readonly IHubContext<GameHub> _hubContext;
public GameHub(IGameService gameService, IDbContextFactory<SlipItInDbContext> contextFactory, ILogger<GameHub> logger)
public GameHub(
IGameService gameService,
IDbContextFactory<SlipItInDbContext> contextFactory,
ILogger<GameHub> logger,
IHubContext<GameHub> hubContext)
{
_gameService = gameService;
_contextFactory = contextFactory;
_logger = logger;
_hubContext = hubContext;
}
/// <summary>
@@ -260,10 +266,10 @@ public class GameHub : Hub
var targetP = await db.Players.FindAsync(playerId);
if (targetP?.ConnectionId != null)
{
await Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand);
await _hubContext.Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand);
}
await Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState);
await _hubContext.Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState);
}
}
catch (Exception ex)