-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLexBoxKernel.cs
More file actions
110 lines (106 loc) · 4.61 KB
/
LexBoxKernel.cs
File metadata and controls
110 lines (106 loc) · 4.61 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using LexBoxApi.Auth;
using LexBoxApi.Config;
using LexBoxApi.GraphQL;
using LexBoxApi.GraphQL.CustomTypes;
using LexBoxApi.Proxies;
using LexBoxApi.Services;
using LexBoxApi.Services.Email;
using LexBoxApi.Services.FwLiteReleases;
using LexCore.Config;
using LexCore.ServiceInterfaces;
using LexSyncReverseProxy;
using LfClassicData;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Polly;
using Swashbuckle.AspNetCore.Swagger;
namespace LexBoxApi;
public static class LexBoxKernel
{
public const string SwaggerDocumentName = "v1";
public const string OpenApiPublicDocumentName = "public";
public static void AddLexBoxApi(this IServiceCollection services,
ConfigurationManager configuration,
IWebHostEnvironment environment)
{
services.AddOptions<HgConfig>()
.BindConfiguration("HgConfig")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<CloudFlareConfig>()
.BindConfiguration("CloudFlare")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<GoogleOptions>()
.BindConfiguration("Authentication:Google")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<EmailConfig>()
.BindConfiguration("Email")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<TusConfig>()
.BindConfiguration("Tus")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<MediaFileConfig>()
.BindConfiguration("MediaFileConfig")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<HealthChecksConfig>()
.BindConfiguration("HealthChecks")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<FwLiteReleaseConfig>()
.BindConfiguration("FwLiteRelease")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<MaintenanceModeConfig>()
.BindConfiguration("MaintenanceMode")
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddHttpClient();
services.AddServiceDiscovery();
services.AddHttpClient<FwHeadlessClient>(client => client.BaseAddress = new ("http://fwHeadless"))
.AddServiceDiscovery();//service discovery means that we lookup the hostname in Services__fwHeadless__http in config
services.AddHttpContextAccessor();
services.AddMemoryCache();
services.AddScoped<LoggedInContext>();
services.AddScoped<IPermissionService, PermissionService>();
services.AddScoped<ProjectService>();
services.AddScoped<CrdtCommitService>();
services.AddScoped<UserService>();
services.AddScoped<IEmailService, EmailService>();
services.AddScoped<TusService>();
services.AddScoped<TurnstileService>();
services.AddScoped<IHgService, HgService>();
services.AddSingleton<FwLiteReleaseService>();
services.AddHostedService<HgService>();
services.AddTransient<HgWebHealthCheck>();
services.AddTransient<FwHeadlessHealthCheck>();
services.AddScoped<ILexProxyService, LexProxyService>();
services.AddSingleton<ISendReceiveService, SendReceiveService>();
services.AddSingleton<LexboxLinkGenerator>();
if (environment.IsDevelopment())
services.AddHostedService<SwaggerValidationService>();
services.AddScheduledTasks(configuration);
services.AddHealthChecks()
.AddCheck<HgWebHealthCheck>("hgweb", HealthStatus.Unhealthy, ["hg"], TimeSpan.FromSeconds(5))
//todo enable this once we want to make lexbox depend on fw-headless
// .AddCheck<FwHeadlessHealthCheck>("fw-headless", HealthStatus.Unhealthy, ["fw-headless"], TimeSpan.FromSeconds(5))
;
services.AddSyncProxy();
services.AddFileUploadProxy();
AuthKernel.AddLexBoxAuth(services, configuration, environment);
services.AddLexGraphQL(environment);
}
private class SwaggerValidationService(IAsyncSwaggerProvider swaggerProvider): BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
//this delay is because there's some kind of race condition where minimal apis are not yet registered
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
await swaggerProvider.GetSwaggerAsync(SwaggerDocumentName);
}
}
}