Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

..NET 8 Blazor and dependency injection: refresh error

$
0
0

In my .NET 8 Blazor solution, I created a project for the application's services, such as API calls.

In the Program.cs in the server project, I added the dependency like this:

builder.Services.AddScoped<ClientService>();

Then, in the client project, on the page, I use the Inject to get an instance of the service like

@rendermode InteractiveAuto@code {    [Inject] public ClientService? _clientService { get; set; }}

The first time the page is loaded, it works fine. However, if I refresh the page, for example, with Ctrl+F5, the _clientService is null.

enter image description here

How can I avoid this error?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>