-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
90 lines (78 loc) · 3.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Headway.BlazorWebassemblyApp;
using Headway.BlazorWebassemblyApp.Account;
using Headway.BlazorWebassemblyApp.Extensions;
using Headway.Core.Cache;
using Headway.Core.Interface;
using Headway.Core.Notifications;
using Headway.Razor.Controls.Services;
using Headway.RemediatR.Core.Model;
using Headway.RequestApi.Api;
using Headway.RequestApi.Requests;
using MediatR;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor.Services;
using System;
using System.Net.Http;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddOidcAuthentication(options =>
{
var identityProvider = builder.Configuration["IdentityProvider:DefaultProvider"];
builder.Configuration.Bind(identityProvider, options.ProviderOptions);
options.UserOptions.RoleClaim = "role";
options.ProviderOptions.ResponseType = "code";
options.ProviderOptions.AdditionalProviderParameters.Add("audience", builder.Configuration[$"{identityProvider}:Audience"]);
}).AddAccountClaimsPrincipalFactory<UserAccountFactory>();
builder.Services.AddHttpClient("webapi", (sp, client) =>
{
client.BaseAddress = new Uri("https://localhost:44320");
}).AddHttpMessageHandler(sp =>
{
var handler = sp.GetService<AuthorizationMessageHandler>()
.ConfigureHandler(
authorizedUrls: new[] { "https://localhost:44320" },
scopes: new[] { "webapi" });
return handler;
});
builder.Services.AddSingleton<IAppCache, AppCache>();
builder.Services.AddSingleton<IConfigCache, ConfigCache>();
builder.Services.AddSingleton<IStateNotification, StateNotification>();
builder.Services.AddTransient<IShowDialogService, ShowDialogService>();
builder.Services.AddTransient<ModulesGetRequestHandler>();
builder.Services.AddTransient<ConfigGetByNameRequestHandler>();
builder.Services.AddTransient<OptionItemsRequestHandler>();
builder.Services.AddTransient<IModuleApiRequest, ModuleApiRequest>(sp =>
{
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("webapi");
return new ModuleApiRequest(httpClient);
});
builder.Services.AddTransient<IConfigurationApiRequest, ConfigurationApiRequest>(sp =>
{
var configCache = sp.GetRequiredService<IConfigCache>();
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("webapi");
return new ConfigurationApiRequest(httpClient, configCache);
});
builder.Services.AddTransient<IDynamicApiRequest, DynamicApiRequest>(sp =>
{
var configCache = sp.GetRequiredService<IConfigCache>();
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("webapi");
return new DynamicApiRequest(httpClient, configCache);
});
builder.Services.AddTransient<IOptionsApiRequest, OptionsApiRequest>(sp =>
{
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("webapi");
return new OptionsApiRequest(httpClient);
});
builder.Services.AddMediatR(typeof(ModuleApiRequest).Assembly);
builder.Services.AddMudServices();
builder.Services.UseAdditionalAssemblies(new[] { typeof(Redress).Assembly });
await builder.Build().RunAsync();