using System.Net.Http.Json; using Blazored.LocalStorage; using GameIdeas.BlazorApp; using GameIdeas.BlazorApp.Pages.Games.Gateways; using GameIdeas.BlazorApp.Pages.UserMenu.Gateways; using GameIdeas.BlazorApp.Pages.Users.Gateways; using GameIdeas.BlazorApp.Services; using GameIdeas.Resources; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; var builder = WebAssemblyHostBuilder.CreateDefault(args); var services = builder.Services; builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); UriBuilder uriBuilder = new(builder.HostEnvironment.BaseAddress); #if DEBUG { uriBuilder.Port = 8000; } #endif services.AddHttpClient( "GameIdeas.WebAPI", client => { client.BaseAddress = uriBuilder.Uri; client.Timeout = TimeSpan.FromMinutes(3); }); services.AddBlazoredLocalStorage(); services.AddAuthorizationCore(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); var app = builder.Build(); await FetchTranslation(app); await app.RunAsync(); static async Task FetchTranslation(WebAssemblyHost app) { var client = app.Services.GetService()?.CreateClient("GameIdeas.WebAPI") ?? throw new Exception("Http client not found"); var response = await client.GetAsync("api/Translations"); var dictionary = await response.Content.ReadFromJsonAsync>(); if (dictionary != null) { app.Services.GetService()!.Initialize(dictionary); ResourcesKey.Initialize(app.Services.GetService()!); } }