I was just wondering why the recommended solution for a Blazor-Server-Chat by Microsoft is initializing a Signal R Hub. Technically, all the C# Code is executed on the server, so it's also possible to realize the chat with a singleton:
public class MySingleton
{
public event Action<string> OnBroadcast
public void Send(string msg)
{
OnBroadcast.Invoke(msg);
}
}
In the Blazor-Component I consume this singleton, subscribe to the event, and call Send(...)
.
Why I should realize this Chat with a separate SignalR Hub?