Olá,
Estou com o seguinte erro ao iniciar o projeto do ScreenSound.Web:
Segue abaixo meus arquivos:
Program.cs
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using ScreenSounds.Web;
using ScreenSounds.Web.Services;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddTransient<ArtistAPI>();
builder.Services.AddHttpClient("API", client => {
client.BaseAddress = new Uri(builder.Configuration["APIServer:Url"]!);
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
await builder.Build().RunAsync();
Services/ArtistAPI.cs
using System.Net.Http.Json;
using ScreenSounds.Web.Requests;
namespace ScreenSounds.Web.Services;
public class ArtistAPI
{
private readonly HttpClient _httpClient;
public ArtistAPI(IHttpClientFactory factory)
{
_httpClient = factory.CreateClient("API");
}
public async Task<ICollection<ArtistRequest>?> GetArtistsAsync()
{
return await _httpClient.GetFromJsonAsync<ICollection<ArtistRequest>>("artists");
}
}
Pages/Artist.razor
@page "/artist"
@inject ArtistAPI artistAPI
<h3>Artist</h3>
@if (artists is not null)
{
foreach (var artist in artists)
{
<p>@artist.name</p>
}
}
@code {
private ICollection<ArtistRequest>? artists;
protected override async Task OnInitializedAsync()
{
artists = await artistAPI.GetArtistsAsync();
}
}
wwwroot/appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"APIServer": {
"Url": "http://localhost:5205"
}
}
Desde já eu agradeço!