Coursach/Course/ImplementerApp/Program.cs

74 lines
2.9 KiB
C#
Raw Normal View History

2024-05-23 20:02:34 +04:00
using BusinessLogic.BusinessLogic;
2024-05-28 19:21:01 +04:00
using BusinessLogic.MailWorker;
using BusinessLogic.OfficePackage;
using BusinessLogic.OfficePackage.Implements;
using Contracts.BusinessLogicsContracts;
2024-05-23 20:02:34 +04:00
using Contracts.StoragesContracts;
using DatabaseImplement.Implements;
using ImplementerApp;
2024-04-28 17:11:40 +04:00
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
2024-04-28 17:11:40 +04:00
2024-05-23 20:02:34 +04:00
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
builder.Services.AddTransient<IDetailStorage, DetailStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
2024-05-26 23:23:24 +04:00
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
2024-05-27 22:06:37 +04:00
builder.Services.AddTransient<IWorkshopStorage, WorkshopStorage>();
2024-05-23 20:02:34 +04:00
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
2024-05-29 22:02:05 +04:00
builder.Services.AddTransient<IImplementerReportLogic, ImplementerReportLogic>();
2024-05-23 20:02:34 +04:00
builder.Services.AddTransient<IDetailLogic, DetailLogic>();
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
2024-05-26 23:23:24 +04:00
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
2024-05-27 22:06:37 +04:00
builder.Services.AddTransient<IWorkshopLogic, WorkshopLogic>();
2024-05-28 19:21:01 +04:00
builder.Services.AddTransient<AbstractSaveToExcelImplementer, SaveToExcelImplementer>();
builder.Services.AddTransient<AbstractSaveToWordImplementer, SaveToWordImplementer>();
builder.Services.AddTransient<AbstractSaveToPdfImplementer, SaveToPdfImplementer>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
2024-05-23 20:02:34 +04:00
builder.Services.AddTransient<ImplementerData>();
2024-05-26 23:23:24 +04:00
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
2024-05-23 20:02:34 +04:00
2024-04-28 17:11:40 +04:00
var app = builder.Build();
2024-05-28 19:21:01 +04:00
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new()
{
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
});
2024-04-28 17:11:40 +04:00
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
2024-04-28 17:11:40 +04:00
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
2024-05-26 23:23:24 +04:00
app.UseSession();
2024-04-28 17:11:40 +04:00
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
2024-04-28 17:11:40 +04:00
app.Run();