Files
game-ideas/src/GameIdeas/Client/GameIdeas.BlazorApp/Program.cs
egamorf76 8efa27e1dd
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 37s
deploy to root user
2025-04-28 20:15:44 +02:00

67 lines
2.0 KiB
C#

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>("#app");
builder.RootComponents.Add<HeadOutlet>("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<AuthenticationStateProvider, JwtAuthenticationStateProvider>();
services.AddScoped<IHttpClientService, HttpClientService>();
services.AddScoped<IAuthGateway, AuthGateway>();
services.AddScoped<IGameGateway, GameGateway>();
services.AddScoped<IUserGateway, UserGateway>();
services.AddSingleton<TranslationService>();
services.AddSingleton<Translations>();
var app = builder.Build();
await FetchTranslation(app);
await app.RunAsync();
static async Task FetchTranslation(WebAssemblyHost app)
{
var client = app.Services.GetService<IHttpClientFactory>()?.CreateClient("GameIdeas.WebAPI") ??
throw new Exception("Http client not found");
var response = await client.GetAsync("api/Translations");
var dictionary = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>();
if (dictionary != null)
{
app.Services.GetService<TranslationService>()!.Initialize(dictionary);
ResourcesKey.Initialize(app.Services.GetService<Translations>()!);
}
}