decePubClient/Program.cs

68 lines
2.7 KiB
C#
Raw Permalink Normal View History

2022-02-02 20:26:14 +01:00
using decePubClient;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2022-02-14 01:51:52 +01:00
using System.Net.Http.Headers;
using System.Text.Json;
using Blazored.LocalStorage;
using decePubClient.Extensions;
2022-02-15 16:15:17 +01:00
using decePubClient.Models;
2022-02-14 01:51:52 +01:00
using decePubClient.Services;
using Toolbelt.Blazor.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Components.Authorization;
2022-12-15 20:03:40 +01:00
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.Extensions.DependencyInjection.Extensions;
2022-02-15 16:15:17 +01:00
using Microsoft.Extensions.Options;
2022-12-15 20:03:40 +01:00
using SocialPub.ClientModels;
using collAnon.Client.Services;
2022-02-02 20:26:14 +01:00
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
2022-12-15 20:03:40 +01:00
builder.RootComponents.Add<HeadOutlet>("head::after");
2022-02-14 01:51:52 +01:00
builder.Services.AddBlazorDownloadFile();
2022-12-15 20:03:40 +01:00
builder.Services.AddApiAuthorization();
2022-02-14 01:51:52 +01:00
builder.Services.AddOptions()
2022-12-15 20:03:40 +01:00
.AddAuthorizationCore(options =>
{
options.AddPolicy(Policies.IsAdmin, ExtensionMethods.IsAdminPolicy());
options.AddPolicy(Policies.IsUser, ExtensionMethods.IsUserPolicy());
options.AddPolicy(Policies.IsModerator, ExtensionMethods.IsUserModeratorPolicy());
})
2022-02-14 01:51:52 +01:00
.AddTransient<AppStatusService>();
2022-12-15 20:03:40 +01:00
builder.Services.TryAddEnumerable(
ServiceDescriptor.Singleton<IPostConfigureOptions<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>>,
ApiAuthorizationOptionsConfiguration>());
builder.Services.AddBlazoredLocalStorage(config =>
{
config.JsonSerializerOptions.WriteIndented = false;
config.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
config.JsonSerializerOptions.IgnoreReadOnlyProperties = true;
config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
})
.AddScoped<TokenAuthStateProvider>()
2022-02-14 01:51:52 +01:00
.AddScoped<MessagesService>()
2022-12-15 20:03:40 +01:00
.AddScoped<AuthenticationStateProvider>(provider => provider.GetRequiredService<TokenAuthStateProvider>())
.AddSingleton(typeof(CoalescingStringLocalizer))
2022-02-14 01:51:52 +01:00
//.AddTransient<IHttpService, HttpService>()
.AddHeadElementHelper(options => options.DisableClientScriptAutoInjection = true)
.AddLocalization()
.AddTransient<IStorage, Storage>()
2022-12-15 20:03:40 +01:00
.AddLogging(lb => lb.SetMinimumLevel(LogLevel.Debug))
2022-02-14 01:51:52 +01:00
.AddIndexedDb();
builder.Services.AddHttpClient("default", client =>
{
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
});
2022-02-15 16:15:17 +01:00
builder.Services.AddSingleton(serviceProvider =>
{
var conf = serviceProvider.GetRequiredService<IConfiguration>();
return conf.GetSection(nameof(AppConfiguration)).Get<AppConfiguration>();
});
2022-02-02 20:26:14 +01:00
2022-02-14 01:51:52 +01:00
var host = builder.Build();
await host.SetDefaultCulture();
await host.RunAsync();