Skip to content
Shiny.NET

MAUI & Blazor

Store state in SQLite through Shiny.DocumentDb:

builder.Services.AddShinyActors(actors => actors.UseDocumentDb(
new SqliteDatabaseProvider($"Data Source={Path.Combine(FileSystem.AppDataDirectory, "actors.db")}")
));

The OS can kill a backgrounded app without warning. Either use [AutoSave] (or actors.UseAutoSave() for every actor), so nothing ever lives only in memory, or flush when the app sleeps:

protected override async void OnSleep() => await actorSystem.DeactivateAllAsync(); // ActorSystem from DI

Actors run in the browser too. Store state in IndexedDB through Shiny.DocumentDb. Because the IndexedDB store is created by the container, call UseDocumentDb() with no arguments:

builder.Services.AddSingleton<IDocumentStore>(sp =>
{
var options = new IndexedDbDocumentStoreOptions
{
DatabaseName = "my-app",
JsonSerializerOptions = new JsonSerializerOptions { TypeInfoResolver = ActorDocumentsJsonContext.Default },
UseReflectionFallback = false
};
return new IndexedDbDocumentStore(options.MapActorDocuments(), sp);
});
builder.Services.AddShinyActors(x => x.UseDocumentDb()); // the IndexedDB store registered above

Reminders fire while the tab is open. A remote client works from the browser as well, as long as the server allows the page’s origin.