using Expose.MyIT.Shared.ViewModels; using Microsoft.AspNetCore.Components; using System.Net.Http.Json; namespace Expose.MyIT.Client.Pages; public partial class FetchData { [Inject] protected HttpClient? HttpClient { get; set; } [Inject] protected ILogger? Logger { get; set; } private WeatherForecast[]? _Forecasts; protected override async Task OnInitializedAsync() { if (Logger is null) throw new NullReferenceException(nameof(Logger)); if (HttpClient is null) throw new NullReferenceException(nameof(HttpClient)); string controllerName = MyIT.Shared.Models.Stateless.IWeatherForecastController.GetRouteName(); try { _Forecasts = await HttpClient.GetFromJsonAsync($"api/{controllerName}"); } catch (Exception) { string json = await HttpClient.GetStringAsync($"api/{controllerName}"); Logger.LogInformation(message: json); } } }