- Added central AddEnvelopeGenerator extension to aggregate existing DI setups - Introduced EGConfiguration for modular service registration - Standardized configuration pattern for Application and Infrastructure layers - Simplified distributed cache and localization registration
63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using EnvelopeGenerator.Application;
|
|
using EnvelopeGenerator.Finalizer;
|
|
using EnvelopeGenerator.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Serilog;
|
|
|
|
// Load Serilog from appsettings.json
|
|
Log.Logger = new LoggerConfiguration()
|
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
.Build())
|
|
.CreateLogger();
|
|
|
|
try
|
|
{
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
// add serilog
|
|
builder.Logging.ClearProviders();
|
|
builder.Logging.AddSerilog();
|
|
|
|
var config = builder.Configuration;
|
|
builder.Services.AddHostedService<Worker>();
|
|
|
|
#region Add DB Context, EG Inf. and Services
|
|
var cnnStrName = "Default";
|
|
var connStr = config.GetConnectionString(cnnStrName)
|
|
?? throw new InvalidOperationException($"Connection string '{cnnStrName}' is missing in the application configuration.");
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
builder.Services.AddEGInfrastructureServices(
|
|
opt =>
|
|
{
|
|
opt.AddDbTriggerParams(config);
|
|
opt.AddDbContext((provider, options) =>
|
|
{
|
|
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
|
options.UseSqlServer(connStr)
|
|
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
|
.EnableSensitiveDataLogging()
|
|
.EnableDetailedErrors();
|
|
});
|
|
});
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
builder.Services.AddEnvelopeGeneratorServices(config);
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
#endregion Add DB Context, EG Inf. and Services
|
|
|
|
var host = builder.Build();
|
|
host.Run();
|
|
|
|
Log.Information("The worker was stopped.");
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Log.Fatal(ex, "Worker could not be started!");
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
} |