using System.Collections.Concurrent; namespace AsbCloudWebApi.SignalR.Services; public class ConnectionManagerService { private readonly ConcurrentDictionary connections = new(); public void AddOrUpdateConnection(int userId, string connectionId) { connections.AddOrUpdate(userId, connectionId, (key, existingConnectionId) => connectionId); } public void RemoveConnection(int userId) { connections.TryRemove(userId, out _); } public string? GetConnectionIdByUserId(int userId) { connections.TryGetValue(userId, out var connectionId); return connectionId; } }