SHA256
Initial implementation for address search/query using external APIs (OSM Nominatim) & Added required classes for supporting more APIs in the future.
84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using FluentValidation;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MudBlazor.Services;
|
|
using Somnia.GuestLog.Components;
|
|
using Somnia.GuestLog.Infrastructure;
|
|
using Somnia.GuestLog.Models.Configuration;
|
|
using Somnia.GuestLog.Models.DTOs;
|
|
using Somnia.GuestLog.Services;
|
|
using Somnia.GuestLog.Services.AddressQuery;
|
|
using Somnia.GuestLog.Utils;
|
|
using Somnia.GuestLog.Validators;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var connectionStringGuestLog = builder.Configuration.GetConnectionString("DbSomniaGuestLog")
|
|
?? throw new InvalidOperationException("Connection string 'DbSomniaGuestLog' not found.");
|
|
builder.Services.AddDbContextFactory<GuestLogContext>(options =>
|
|
{
|
|
options.UseNpgsql(connectionStringGuestLog);
|
|
});
|
|
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
// Add MudBlazor services
|
|
builder.Services.AddMudServices();
|
|
|
|
// Add components services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.Services.AddLocalization();
|
|
builder.Services.AddHttpClient();
|
|
|
|
// Add Validation Services
|
|
builder.Services.AddSingleton<IValidator<GuestDocumentDTO>, GuestDocumentDTOValidator>();
|
|
builder.Services.AddSingleton<IValidator<GuestDocIdDTO>, GuestDocIdDTOValidator>();
|
|
|
|
// Add Services
|
|
builder.Services.AddSingleton<IGuestDocumentService, GuestDocumentService>();
|
|
builder.Services.AddSingleton<IDataListService, StaticDataListService>();
|
|
|
|
// Add Factories (and it's services)
|
|
builder.Services.AddFactoryDI<IAddressQueryFactory, ConfigFileAddressQueryFactory>();
|
|
|
|
// Add Options config
|
|
builder.Services.AddOptions<AddressQueryConfig>()
|
|
.Bind(builder.Configuration.GetSection(AddressQueryConfig.SectionName));
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseMigrationsEndPoint();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// 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.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAntiforgery();
|
|
|
|
string[] supportedCultures = ["en-US", "es-ES"];
|
|
var localizationOptions = new RequestLocalizationOptions()
|
|
.SetDefaultCulture(supportedCultures[0])
|
|
.AddSupportedCultures(supportedCultures)
|
|
.AddSupportedUICultures(supportedCultures);
|
|
localizationOptions.RequestCultureProviders = [
|
|
new QueryStringRequestCultureProvider(),
|
|
new CookieRequestCultureProvider()
|
|
];
|
|
|
|
app.UseRequestLocalization(localizationOptions);
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
app.Run();
|