Files

79 lines
3.6 KiB
C#
Raw Permalink Normal View History

2021-04-02 21:45:14 +02:00
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
2021-05-14 13:29:07 +02:00
using System.Diagnostics;
2021-04-07 12:32:17 +02:00
using System.Globalization;
2021-04-02 21:45:14 +02:00
using System.Net.Http;
using System.Threading.Tasks;
using MediatR;
2021-04-07 12:32:17 +02:00
using Microsoft.JSInterop;
2021-04-03 15:43:31 +02:00
using Radzen;
2021-04-07 12:32:17 +02:00
using WotBlitzStatisticsPro.Blazor.Model;
using WotBlitzStatisticsPro.Blazor.Services;
2021-06-02 10:34:19 +02:00
using WotBlitzStatisticsPro.Blazor.Services.Mock;
2021-09-02 18:43:00 +02:00
using WotBlitzStatisticsPro.Blazor.GraphQl;
2021-04-02 21:45:14 +02:00
namespace WotBlitzStatisticsPro.Blazor
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
2021-04-07 12:32:17 +02:00
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
2021-04-02 21:45:14 +02:00
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
2021-04-03 15:43:31 +02:00
builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<NotificationService>();
2021-07-15 11:51:06 +02:00
builder.Services.AddScoped<TooltipService>();
builder.Services.AddScoped<ISearchDialogService, SearchDialogService>();
2021-08-02 15:05:22 +02:00
builder.Services.AddScoped<IChartsService, ChartService>();
2021-10-25 18:34:55 +03:00
builder.Services.AddScoped<IMediaQueriesService, MediaQueriesService>();
2022-05-05 12:28:16 +02:00
builder.Services.AddScoped<ITankStatisticDialogService, TankStatisticDialogService>();
2022-05-06 12:05:12 +02:00
builder.Services.AddScoped<IMedalDialogService, MedalDialogService>();
2022-07-21 13:20:59 +02:00
builder.Services.AddScoped<ISvgHelper, SvgHelper>();
builder.Services.AddMediatR(typeof(Program));
2021-04-03 15:43:31 +02:00
builder.Services.AddSingleton<NavigationMessagesInterceptor>();
2021-04-07 12:32:17 +02:00
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
builder.Services.AddSingleton<INotificationsService, NotificationsService>();
2021-09-02 18:43:00 +02:00
builder.Services.AddSingleton<IWargamingAuthTokenHeaderHelper, WargamingAuthTokenHeaderHelper>();
builder.Services.AddTransient<WargamingAuthTokenHeaderHandler>();
2021-05-14 11:37:45 +02:00
// StrawberryShake GraphQL Client
2021-09-02 18:43:00 +02:00
builder.Services.AddHttpClient(
WotBlitzStatisticsProClient.ClientName,
client => client.BaseAddress = new Uri($"{builder.HostEnvironment.BaseAddress}graphql/"))
.AddHttpMessageHandler<WargamingAuthTokenHeaderHandler>();
builder.Services.AddWotBlitzStatisticsProClient();
2021-05-14 11:37:45 +02:00
// ToDo: Asp Net hosting environment variables don't work here. I don't know why
//var useMock = Environment.GetEnvironmentVariable("USE_GRAPH_QL_MOCK");
//if (useMock != null && useMock == "true")
//{
2022-08-22 15:16:05 +02:00
//builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendMockService>();
//}
//else
//{
2022-08-22 15:16:05 +02:00
builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendService>();
//}
2021-05-14 11:37:45 +02:00
2021-04-07 12:32:17 +02:00
var host = builder.Build();
// Reading Current Culture from LocalStorage
var localStorageService = host.Services.GetRequiredService<ILocalStorageService>();
var settings = await localStorageService.GetItemAsync<UserSettings>(UserSettings.UserSettingsLocalStorageKey);
if (settings != null)
{
var culture = new CultureInfo(settings.Culture);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
await host.RunAsync();
2021-04-02 21:45:14 +02:00
}
}
}