https://github.com/xevilmaxx/blazorserverpushsignalr
Sample of how to use Blazor + SignalR tech (C# Net 5.0). Mainly how to have a static object to use in any place server side in order to push signalR notification to connected clients.
https://github.com/xevilmaxx/blazorserverpushsignalr
aspnet aspnetcore blazor csharp css html linux net5 razor signalr
Last synced: about 2 months ago
JSON representation
Sample of how to use Blazor + SignalR tech (C# Net 5.0). Mainly how to have a static object to use in any place server side in order to push signalR notification to connected clients.
- Host: GitHub
- URL: https://github.com/xevilmaxx/blazorserverpushsignalr
- Owner: xevilmaxx
- Created: 2021-07-02T09:48:33.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-02T10:10:36.000Z (about 5 years ago)
- Last Synced: 2025-07-28T12:36:28.004Z (11 months ago)
- Topics: aspnet, aspnetcore, blazor, csharp, css, html, linux, net5, razor, signalr
- Language: C#
- Homepage:
- Size: 327 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BlazorServerPushSignalr
Sample of how to use Blazor + SignalR tech (C# Net 5.0). Mainly how to have a static object to use in any place server side in order to push signalR notification to connected clients.
## Solution based on:
- - -
https://newbedev.com/how-to-get-signalr-hub-context-in-a-asp-net-core
- - -
https://stackoverflow.com/questions/51968201/invoking-signalr-hub-not-working-for-asp-net-core-web-api/51981886#51981886
- - -
### I assume you know how Blazor app is basically structured
### Main Points to focalize on:
- [x] Startup.cs
- [x] Hubs/SignalrHub0.cs
- [x] Pages/Index.razor
- [x] Controllers/IndexController.cs
- [x] Statics/SignalrServerSide.cs
### Basic Idea:
- - -
You have your Index.razor (layout only)
**Index.razor** is controlled by **IndexController.cs**
### Basic Workflow
- - -
In **Startup.cs** you will map your Hub (**SignalrHub0.cs**) on certain endpoint.
Backend of startup will automatically call constructor of **SignalrHub0.cs** with needed data.
- - -
You will also need to define a Hosted Service (**SignalrServerSide.cs**) which we will use later as main endpoint to access HubClients at any point directly from backend.
Again, **Startup.cs** backend will keep updated static variable in SignalrServerSide.cs with its strange logics.
- - -
Now all you need to do to get all currently connected clients at any point on server side:
**SignalrServerSide.HubContext**
- - -
If you wish to recycle logics you already defined in SignalrHub0.cs
Thanks to its constructor you can simply do this:
**_ = new SignalrHub0(SignalrServerSide.HubContext).SendMessageAsync("MyRecycledMessage");**