Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Implements and reviews ASP.NET Core SignalR hubs, streaming, reconnection, transports, and real-time group broadcasting patterns.
95% 100%+5 ptsof test cases passed
Passed 22 of 22 test cases with the skill, and 21 of 22 without it.
3 of 3 safety checks passed
This reference documents common SignalR mistakes and how to avoid them.
Hub instances are transient and created per invocation:
// BAD: State is lost between calls
public class BadHub : Hub
{
private List<string> _messages = new(); // Created fresh every call
private int _messageCount = 0; // Always 0
public Task SendMessage(string message)
{
_messages.Add(message); // Lost immediately
_messageCount++; // Always 1
return Task.CompletedTask;
}
}
// GOOD: Use external state management
public class GoodHub : Hub
{
private readonly IMessageStore _store;
private readonly IMemoryCache _cache;
public GoodHub(IMessageStore store, IMemoryCache cache)
{
_store = store;
_cache = cache;
}
public async Task SendMessage(string message)
{
await _store.AddMessageAsync(message);
Next to this one in the catalogue, plus more from the same author.