Files
monorepo/LCU.WebApps.Internal.DocumentManager/LCU.WebApps.Internal.DocumentManager/Program.cs
T
2026-03-13 09:24:21 -05:00

139 lines
6.3 KiB
C#

using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
using Serilog;
using Blazored.Modal;
using Blazored.Toast;
using Blazored.Toast.Services;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
using LCU.Library.Internal.Logging;
using LCU.Library.Internal.Logging.Models;
using LCU.Library.Internal.Configuration;
using LCU.WebApps.Internal.DocumentManager.Authentication;
using LCU.WebApps.Internal.DocumentManager.Configurations;
using LCU.WebApps.Internal.DocumentManager.Services;
using LCU.WebApps.Internal.DocumentManager.Services.Decorators;
using Microsoft.AspNetCore.Authorization;
using LCU.WebApps.Internal.DocumentManager.Shared.DocumentGridView;
using LCU.WebApps.Internal.DocumentManager.Shared.JSInterop;
using LCU.Library.Internal.Security;
using LCU.Library.Internal.LcuHttpClient;
var builder = BuildBuilder(args);
BuildServicesAndConfigurations(builder);
BuildAppAndRun(builder);
WebApplicationBuilder BuildBuilder(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("/app/config/environment-appsettings/appsettings.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/app/config/workload-appsettings/appsettings.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/document-manager-seq-api-key.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/document-manager-client-secret.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/document-manager-client-id.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/document-manager-api-key.json", optional: true, reloadOnChange: true);
builder.Host.UseSerilog();
if (builder.Environment.EnvironmentName.Contains("Local", StringComparison.OrdinalIgnoreCase))
{
builder.WebHost.UseStaticWebAssets();
}
return builder;
}
void BuildServicesAndConfigurations(WebApplicationBuilder builder)
{
var services = builder.Services;
var configuration = builder.Configuration;
services.AddRazorPages();
// Add services to the container.
services.AddAzureAdGroupPolicyServicesWithToken(configuration.GetSection("AzureAd"),
configuration.GetSection("Security"));
services.AddControllersWithViews().AddMicrosoftIdentityUI();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
services.AddHttpClient();
services.AddLCUHttpServices();
services.AddHttpContextAccessor();
var appConfiguration = configuration.Bind<AppConfiguration>(services, "Primary");
configuration.Bind<CoreApiWrapperConfiguration>(services);
configuration.Bind<DocumentIngestorApiConfiguration>(services);
configuration.Bind<FileOperationsApiConfiguration>(services);
var documentTypeRetrieverConfiguration = configuration.Bind<DocumentTypeRetrieverApiConfiguration>(services);
configuration.Bind<DocumentTypeUploaderApiConfiguration>(services);
var loggerConfiguration = new LoggingConfiguration(appConfiguration.AppName,
appConfiguration.SeqApiKey,
appConfiguration.SeqUrl);
var lcuLogging = new LcuLogging(loggerConfiguration);
lcuLogging.UseLcuLogging();
AddDocumentManagerServices(services);
AddBlazoreAdditionServices(services);
AddJavascriptInterop(services);
services.AddScoped<AuthenticationHelper>();
services.AddTransient<IDocumentCodeDetailsTableViewModel, DocumentCodeDetailsTableViewModel>();
services.AddTransient<ITablePagingViewModel<DocumentProcessingInfo, Filter>, DocumentProcessingInfoTableViewModel>();
services.AddTransient<IBusinessViewViewModel, BusinessViewViewModel>();
}
void AddDocumentManagerServices(IServiceCollection services)
{
services.AddScoped<DocumentProcessingInfoService>();
services.AddScoped<IDocumentProcessingInfoService>(p => new DocumentProcessingInfoServiceErrorDecorator(p.GetRequiredService<DocumentProcessingInfoService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<QueueDocumentReprocessingService>();
services.AddScoped<IDocumentReprocessingService>(p => new DocumentReprocessingServiceErrorDecorator(p.GetRequiredService<QueueDocumentReprocessingService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<CoreApiWrapperService>();
services.AddScoped<IEntityService>(p => new EntityServiceErrorDecorator(p.GetRequiredService<CoreApiWrapperService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<DocumentTypeRetrieverService>();
services.AddScoped<IDocumentService>(p => new DocumentServiceErrorDecorator(p.GetRequiredService<DocumentTypeRetrieverService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<IDocumentTypeService>(p => new DocumentTypeServiceErrorDecorator(p.GetRequiredService<DocumentTypeRetrieverService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<DocumentTypeUploaderService>();
services.AddScoped<IDocumentTypeUploaderService>(p => new DocumentTypeUploaderServiceErrorDecorator(p.GetRequiredService<DocumentTypeUploaderService>(), p.GetRequiredService<IToastService>()));
services.AddScoped<IDocumentAuthorization, BusinessViewViewModel>();
}
void AddBlazoreAdditionServices(IServiceCollection services)
{
services.AddBlazoredToast();
services.AddBlazoredModal();
}
void AddJavascriptInterop(IServiceCollection services)
{
services.AddTransient<IJSDate, JSDate>();
services.AddTransient<IJSDocument, JSDocument>();
services.AddTransient<IJSTooltips, JSTooltips>();
}
void BuildAppAndRun(WebApplicationBuilder builder)
{
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
}