using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Shogi.UI; using Shogi.UI.Pages.Home; using Shogi.UI.Pages.Home.Account; using Shogi.UI.Pages.Home.Api; using Shogi.UI.Shared; using Shogi.UI.Shared.Modal; using System.Net.WebSockets; using System.Text.Json; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); ConfigureDependencies(builder.Services, builder.Configuration); await builder.Build().RunAsync(); static void ConfigureDependencies(IServiceCollection services, IConfiguration configuration) { /** * Why two HTTP clients? * See qhttps://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?source=recommendations&view=aspnetcore-6.0#unauthenticated-or-unauthorized-web-api-requests-in-an-app-with-a-secure-default-client */ var baseUrl = configuration["ShogiApiUrl"]; if (string.IsNullOrWhiteSpace(baseUrl)) { throw new InvalidOperationException("ShogiApiUrl configuration is missing."); } var shogiApiUrl = new Uri(baseUrl, UriKind.Absolute); services .AddHttpClient(ShogiApi.MsalClientName, client => client.BaseAddress = shogiApiUrl) .AddHttpMessageHandler(); services .AddHttpClient(ShogiApi.GuestClientName, client => client.BaseAddress = shogiApiUrl) .AddHttpMessageHandler(); // Authorization services.AddMsalAuthentication(options => { configuration.Bind("AzureAd", options.ProviderOptions.Authentication); options.ProviderOptions.LoginMode = "redirect"; }); services.AddOidcAuthentication(options => { // Configure your authentication provider options here. // For more information, see https://aka.ms/blazor-standalone-auth configuration.Bind("AzureAd", options.ProviderOptions); options.ProviderOptions.ResponseType = "code"; }); // https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-6.0#service-lifetime services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); var serializerOptions = new JsonSerializerOptions { WriteIndented = true }; services.AddScoped((sp) => serializerOptions); }