Blazor Dev Blog

Practical notes on Blazor, ASP.NET Core and the .NET ecosystem.

Service Collections with Blazor Server

Service collections are a way of registering and resolving dependencies in C# applications using the built-in dependency injection (DI) system. Blazor Server is a web framework that allows you to run C# code on the server and interact with the user interface through a SignalR connection. To use…

Read more →

In Memory State Management with Blazor Server

Web technology has come along way in the relatively recent past. With the surge in popularity of SPAs and Javascript Frameworks a lot of developers have come to expect certain functionality out of the box. Blazor Server being a stateful application framework offers us a lot of functionality missing…

Read more →

IHttpClientFactory vs. HttpClient

The main reason to use IHttpClientFactoryinstead of HttpClient directly is to manage the life cycle of HttpClient instances. HttpClient was designed to be instantiated once and reused throughout the application life cycle. If you continually instantiate new HttpClients you may unnecessarily be…

Read more →

How to add HealthChecks to a ASP.net Core application

From Microsoft Out of the box Health Checks UI Add the following Health Check nuget packages to your project solution: This new class injects a repository for sample purposes. You can imagine this service responsible for fetching data from an external API or a database. From there we execute a…

Read more →

Why Is IHttpContextAccessor/HttpContext null on Blazor Server? Here’s how to fix it!

The IHttpContextAccessor on Blazor Server is only available on the first Http request when loading a Blazor Server application. After that, all connections to the server is handled via SignalR. Your HttpContext will most likely be null after this. This may be unfamiliar to you if you’re coming from…

Read more →

Why are you experiencing a NullReferenceException on OnInitializedAsync() with Blazor?

Lets start with a sample Razor component that renders the UI: Component.razor Lets look at the ‘code behind’ (ooof I’m old) AKA a partial class that represents the logic of the component (view) Component.razor.cs The main issue is the way the method OnInitializedAsync() executes in Blazor. It…

Read more →

How can I dynamically render components using MudBlazor radio buttons?

You need to have a MudRadioGroup to contain your MudRadio buttons. On the MudRadioGroup you have the @bind-SelectedOption event callback exposed. You can set a switch statement on that to dynamically render your other components. Parent Component: TestComponent.razor…

Read more →
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.