Service Collections with Blazor Server
What is a service collection? 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 service collections…
In Memory State Management with Blazor Server
Creating your first In Memory State Container 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…
IHttpClientFactory vs. HttpClient
Why should you use IHttpClientFactory 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 squandering resources. Another use case is for simplicities…
How to add HealthChecks to a ASP.net Core application
Adding HealthChecks to your application can drastically reduce troubleshooting time Why would you want to monitor your applications health? Health checks can test an applications dependencies, such as databases and external service endpoints, to confirm availability and normal functioning. From Microsoft Out of the box Health Checks UI Here is how to monitor SQL Server…
Why Is IHttpContextAccessor/HttpContext null on Blazor Server? Here’s how to fix it!
Table of Contents Why is IHttpContextAccessor -or- HttpContext sometimes null on Blazor Server? 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…
Why are you experiencing a NullReferenceException on OnInitializedAsync() with Blazor?
Lets start with a sample Razor component that renders the UI: Component.razor Forename Surname Username @foreach (var user in Users) { @user.Forename @user.Surname @user.Username } 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 public partial class Component { private string _url…
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 Sample Project https://try.mudblazor.com/snippet/wOmRucPSpMDbtnAw