squash a bunch of commits
This commit is contained in:
65
Shogi.UI/Program.cs
Normal file
65
Shogi.UI/Program.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using Shogi.UI;
|
||||
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>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("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 shogiApiUrl = new Uri(configuration["ShogiApiUrl"], UriKind.Absolute);
|
||||
services
|
||||
.AddHttpClient(ShogiApi.MsalClientName, client => client.BaseAddress = shogiApiUrl)
|
||||
.AddHttpMessageHandler<MsalMessageHandler>();
|
||||
services
|
||||
.AddHttpClient(ShogiApi.GuestClientName, client => client.BaseAddress = shogiApiUrl)
|
||||
.AddHttpMessageHandler<CookieCredentialsMessageHandler>();
|
||||
services
|
||||
.AddHttpClient(ShogiApi.AnonymouseClientName, client => client.BaseAddress = shogiApiUrl)
|
||||
.AddHttpMessageHandler<CookieCredentialsMessageHandler>();
|
||||
|
||||
// Authorization
|
||||
services.AddMsalAuthentication(options =>
|
||||
{
|
||||
configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
|
||||
});
|
||||
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<ClientWebSocket>();
|
||||
services.AddScoped<AccountManager>();
|
||||
services.AddScoped<AccountState>();
|
||||
services.AddScoped<ShogiSocket>();
|
||||
services.AddScoped<ModalService>();
|
||||
services.AddScoped<ILocalStorage, LocalStorage>();
|
||||
services.AddScoped<MsalMessageHandler>();
|
||||
services.AddScoped<CookieCredentialsMessageHandler>();
|
||||
services.AddScoped<IShogiApi, ShogiApi>();
|
||||
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
services.AddScoped((sp) => serializerOptions);
|
||||
}
|
||||
Reference in New Issue
Block a user