I am currently learning Blazor Web assembly. So I have created a Blazor Web Assembly sandbox on .Net 6. I want to create an object that can't be reloaded on the entire lifecycle of the app, in order to share it between pages. So, I want to create it as singleton. But I have this error.
Here is the code of Program.cs :
using BlazorAppWebAsmSandbox.Client;using Microsoft.AspNetCore.Components.WebAssembly.Hosting;var builder =WebAssemblyHostBuilder.CreateDefault(args);builder.Services.AddSingleton<GuidObject>();await builder.Build().RunAsync();GuidObject :
namespace BlazorAppWebAsmSandbox.Client{ public class GuidObject { public Guid id { get; set; } = Guid.NewGuid(); }}And here how I use it :
@page "/counter"@rendermode InteractiveWebAssembly@inject GuidObject guidObject<PageTitle>Counter</PageTitle><h1>Counter</h1><p role="status">Current count: @currentCount</p><p role="status">guidObject @guidObject.id</p><button class="btn btn-primary" @onclick="IncrementCount">Click me</button>@code { private int currentCount = 0; private void IncrementCount() { currentCount++; }}Thanks for your help
