79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System.Net;
|
|
using Drab.Core.Configuration;
|
|
using Drab.Core.Ioc;
|
|
using Drab.LocalDb;
|
|
using Drab.LocalDb.IoC;
|
|
using Drab.Logic.Ioc;
|
|
using Drab.Logic.Services;
|
|
using Drab.Ui;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NLog.Extensions.Logging;
|
|
using Pcm.Db.Ioc;
|
|
using Radzen;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
|
var configuration = configurationBuilder.Build();
|
|
|
|
var port = int.Parse(builder.WebHost.GetSetting("ListenPort") ?? "5010");
|
|
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.Services.AddLogging(loggingBuilder =>
|
|
{
|
|
loggingBuilder.ClearProviders();
|
|
loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
|
|
loggingBuilder.AddNLog("nlog.config");
|
|
});
|
|
|
|
var drabSettings = configuration.GetSection(DrabSettings.SectionName).Get<DrabSettings>();
|
|
var localDbSettings = configuration.GetSection(LocalDbConfiguration.SectionName).Get<LocalDbConfiguration>();
|
|
builder.Services.AddLocalDatabase(localDbSettings);
|
|
var dbConfig = configuration.GetSection(PcmDbConfiguration.SectionName).Get<PcmDbConfiguration>();
|
|
|
|
builder.Services.AddPcmDatabase(dbConfig);
|
|
builder.Services.AddDrabCore(drabSettings);
|
|
builder.Services.AddDrabLogic();
|
|
builder.Services.AddHostedService<OldOrdersCleanupService>();
|
|
|
|
builder.Services.AddRadzenComponents();
|
|
builder.Services.AddControllers().AddControllersAsServices();
|
|
builder.WebHost
|
|
.UseKestrel(options =>
|
|
{
|
|
options.Listen(IPAddress.Any, port);
|
|
})
|
|
.UseContentRoot(Directory.GetCurrentDirectory());
|
|
|
|
var app = builder.Build();
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAntiforgery();
|
|
app.MapControllers();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Orders")))
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Orders"));
|
|
}
|
|
|
|
var scope = app.Services.GetService<IServiceScopeFactory>();
|
|
using (var scopeProvider = scope.CreateScope())
|
|
{
|
|
await using var context = scopeProvider.ServiceProvider.GetRequiredService<LocalDbContext>();
|
|
await context.Database.MigrateAsync();
|
|
}
|
|
|
|
app.Run(); |