All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 55s
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System.Net.Http.Json;
|
|
using GameIdeas.BlazorApp;
|
|
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|
using GameIdeas.BlazorApp.Services;
|
|
using GameIdeas.Resources;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
builder.RootComponents.Add<App>("#app");
|
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
|
|
UriBuilder uriBuilder = new(builder.HostEnvironment.BaseAddress)
|
|
{
|
|
Port = 8000
|
|
};
|
|
|
|
builder.Services.AddHttpClient(
|
|
"GameIdeas.WebAPI",
|
|
client =>
|
|
{
|
|
client.BaseAddress = uriBuilder.Uri;
|
|
client.Timeout = TimeSpan.FromMinutes(3);
|
|
});
|
|
|
|
builder.Services.AddScoped<IHttpClientService, HttpClientService>();
|
|
builder.Services.AddScoped<IGameGateway, GameGateway>();
|
|
|
|
builder.Services.AddSingleton<TranslationService>();
|
|
builder.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>()!);
|
|
}
|
|
} |