'Chat Realization with Singleton vs Separate SignalR Hub

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source