PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenRestApi/Program.cs

80 lines
3.2 KiB
C#
Raw Permalink Normal View History

2023-04-09 19:05:54 +04:00
using CanteenBusinessLogic.BusinessLogics;
2023-06-19 09:12:18 +04:00
using CanteenBusinessLogic.MailWorker;
2023-05-20 12:11:48 +04:00
using CanteenBusinessLogic.OfficePackage;
using CanteenBusinessLogic.OfficePackage.Implements;
2023-06-19 09:12:18 +04:00
using CanteenContracts.BindingModels;
2023-04-09 19:05:54 +04:00
using CanteenContracts.BusinessLogicsContracts;
using CanteenContracts.StoragesContracts;
using CanteenDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
builder.Services.AddTransient<IManagerStorage, ManagerStorage>();
2023-05-19 03:39:58 +04:00
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
2023-04-09 19:05:54 +04:00
builder.Services.AddTransient<ICookStorage, CookStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<IDishStorage, DishStorage>();
2023-05-14 22:24:37 +04:00
builder.Services.AddTransient<ITablewareStorage, TablewareStorage>();
2023-05-20 00:18:48 +04:00
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ILunchStorage, LunchStorage>();
2023-04-09 19:05:54 +04:00
builder.Services.AddTransient<IManagerLogic, ManagerLogic>();
2023-05-19 03:39:58 +04:00
builder.Services.AddTransient<IVisitorLogic, VisitorLogic>();
2023-04-09 19:05:54 +04:00
builder.Services.AddTransient<ICookLogic, CookLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<IDishLogic, DishLogic>();
2023-05-14 22:24:37 +04:00
builder.Services.AddTransient<ITablewareLogic, TablewareLogic>();
2023-05-20 00:18:48 +04:00
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
2023-05-17 17:59:48 +04:00
builder.Services.AddTransient<IGraphicLogic, GraphicLogic>();
2023-05-20 00:18:48 +04:00
builder.Services.AddTransient<ILunchLogic, LunchLogic>();
2023-05-20 12:11:48 +04:00
builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
2023-06-19 09:12:18 +04:00
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
2023-05-20 12:11:48 +04:00
2023-04-09 19:05:54 +04:00
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "CanteenRestApi",
Version = "v1"
});
});
var app = builder.Build();
2023-06-19 09:12:18 +04:00
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
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())
});
2023-04-09 19:05:54 +04:00
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CanteenRestApi v1"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();