Skip to content

Blazor

Blazor is a .NET frontend web framework that supports both server-side rendering and client interactivity in a single programming model

  1. Install to your project.
  2. In your Program.cs file, add the following:
builder.Services.AddShinyMediator(cfg => cfg.UseMaui());
  1. Start making calls to the mediator as you normally would

The Blazor event collector is installed by default by UseBlazor. Event collectors allow event handlers that may not be registered with dependency injection/Mediator to still participate in IMediator.Publish calls.

This extension comes with a lot of preinstalled default middleware (that you can opt out of). If you choose to opt-out of this middleware being installed, simply pass false to the first argument in UseMaui

Connectivity is used on almost every page or viewmodel in an app. You almost always have to inject the a connectivity service and hook the StateChanged event to do things like disabling buttons, showing errors, or putting up an banner to let you users know why your app isn’t showing fresh data. That’s a lot of extra code, cleanup, hooks, etc. This is where connectivity broadcaster comes in

  1. In your main lastout, add the <InternetConnectivity /> component

    <InternetConnectivity />
  2. In your pages, controls (in scope of current page), or services, implement the IConnectivityEventHandler interface

    public class MyService : Shiny.Mediator.IConnectivityEventHandler
    {
    public async Task Handle(ConnectivityChanged @event, IMediatorContext context, CancellationToken ct)
    {
    // that's it
    SomeString = @event.Connected ? "Connected" : "Disconnected";
    }
    }

    OR

    @implements Shiny.Mediator.IConnectivityEventHandler
    @code {
    public async Task Handle(ConnectivityChanged @event, IMediatorContext context, CancellationToken ct)
    {
    // that's it
    SomeString = @event.Connected ? "Connected" : "Disconnected";
    await InvokeAsync(StateHasChanged);
    }
    }