Blazor Error: “There is no registered service of type”

  Kiến thức lập trình

There is no registered service, but I am adding the service in the Program.cs class, I am using net8.

@page "/produtos"
@inject IProdutoService produtoService

@code {
    
    public IEnumerable<ProdutoDto>? Produtos { get; set; }

    protected override async Task OnInitializedAsync()
    {
        Produtos = await produtoService.GetItens();
    }
}
using ECommerce.Client.Services;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

//Adicionando a rota para acessar a API
builder.Services.AddScoped(http => new HttpClient { 
    BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
});

// Criando uma instância do serviço
builder.Services.AddScoped<IProdutoService, ProdutoService>();

await builder.Build().RunAsync();

enter image description here

I would like the page to be rendered

New contributor

William Crystian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT