63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
#if POSTGRES
|
|
using MVC_SimpleCRUD_Layered.Data.Data.Postgres;
|
|
#else
|
|
using MVC_SimpleCRUD_Layered.Data.Data.MSSQL;
|
|
#endif
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MVC_SimpleCRUD_Layered.Application.Models;
|
|
using MVC_SimpleCRUD_Layered.Application.People;
|
|
using MVC_SimpleCRUD_Layered.Web;
|
|
using NLog;
|
|
using NLog.Web;
|
|
using Sieve.Services;
|
|
|
|
var logger = NLog.LogManager.Setup().GetCurrentClassLogger();
|
|
logger.Debug("init main");
|
|
try
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.Host.UseNLog(new NLogAspNetCoreOptions() { RemoveLoggerFactoryFilter = false });
|
|
|
|
#region Configure services
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services.Configure<PagingSettings>(builder.Configuration.GetSection(PagingSettings.SectionName));
|
|
#if POSTGRES
|
|
builder.Services.AddDbContext<EventsContext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("EventsPostgres")));
|
|
#else
|
|
builder.Services.AddDbContext<EventsContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("EventsMssql")));
|
|
#endif
|
|
builder.Services.AddScoped<IPeopleService, PeopleService>();
|
|
builder.Services.AddScoped<ISieveProcessor, SieveProcessor>();
|
|
#endregion
|
|
|
|
var app = builder.Build();
|
|
|
|
#region configure middleware pipeline
|
|
//middleware order https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/#middleware-order
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.MapDefaultControllerRoute();
|
|
|
|
#endregion
|
|
app.Run();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
// NLog: catch setup errors
|
|
logger.Error(exception, "Stopped program because of exception");
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
|
|
NLog.LogManager.Shutdown();
|
|
}
|