Iceshrimp.NET/Iceshrimp.Frontend/Startup.cs
2024-09-13 21:44:31 +02:00

46 lines
No EOL
2 KiB
C#

using System.Globalization;
using Blazored.LocalStorage;
using Iceshrimp.Frontend;
using Iceshrimp.Frontend.Core.InMemoryLogger;
using Iceshrimp.Frontend.Core.Miscellaneous;
using Iceshrimp.Frontend.Core.Services;
using Ljbc1994.Blazor.IntersectionObserver;
using Microsoft.AspNetCore.Components.Authorization;
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");
builder.Services.AddSingleton(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddLocalization();
builder.Logging.AddInMemoryLogger(builder.Configuration);
builder.Services.AddSingleton<ApiClient>();
builder.Services.AddSingleton<ApiService>();
builder.Services.AddIntersectionObserver();
builder.Services.AddSingleton<SessionService>();
builder.Services.AddSingleton<StreamingService>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
builder.Services.AddSingleton<ComposeService>();
builder.Services.AddSingleton<StateService>();
builder.Services.AddSingleton<EmojiService>();
builder.Services.AddSingleton<VersionService>();
builder.Services.AddSingleton<MessageService>();
builder.Services.AddSingleton<GlobalComponentSvc>();
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddBlazoredLocalStorageAsSingleton();
// Culture information (locale) has to be set before run.
var host = builder.Build();
var helper = new LocaleHelper(host.Services.GetRequiredService<ISyncLocalStorageService>());
var culture = helper.LoadCulture();
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
var logger = host.Services.GetRequiredService<ILoggerFactory>()
.CreateLogger<Program>();
logger.LogInformation("Starting Iceshrimp.Frontend");
await host.RunAsync();