Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no registered service of type error in blazor.net when adding a new service

Tags:

blazor

I have set up a sample blazor.net application as per the Docs. After that I created a new service and hard-coded few data and trying to run the application.

But I'm receiving the following error in the console:

There is no registered service of type <applicationName>.App.Services.<serviceName>

It seems the new service name need to register some where, how can I register the new service?

like image 757
Arulkumar Avatar asked Feb 19 '19 08:02

Arulkumar


People also ask

How do you handle errors in Blazor?

When an error occurs, Blazor apps display a light yellow bar at the bottom of the screen: During development, the bar directs you to the browser console, where you can see the exception. In production, the bar notifies the user that an error has occurred and recommends refreshing the browser.

How do you display error messages in Blazor?

How do you display a validation message specific to a field in a Blazor form? You have to use the <ValidationMessage> tag with the “For” attribute lambda expression pointing to the form field.

Should I use Blazor server or Blazor Wasm?

The Blazor Server hosting model offers several benefits: Download size is significantly smaller than a Blazor WebAssembly app, and the app loads much faster. -The app takes full advantage of server capabilities, including the use of . NET Core APIs.


1 Answers

Worth noting that for Blazor WebAssembly, there is no Startup class like the one in Blazor Server. In Blazor WebAssembly we can register Services in Program.cs as below:

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);

    //...other services
    builder.Services.AddSingleton<MyNewService>();

    builder.RootComponents.Add<App>("app");
    await builder.Build().RunAsync();
 }
like image 118
gpanagopoulos Avatar answered Sep 18 '22 14:09

gpanagopoulos