PIbd-22_Chernyshev_Shabunov.../ComputerShopRestApi/Program.cs
2024-05-29 17:52:23 +04:00

88 lines
3.6 KiB
C#

using ComputerShopBusinessLogic.BusinessLogics;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.StorageContracts;
using ComputerShopDatabaseImplement.Implements;
using ComputerShopBusinessLogic.MailWorker;
using ComputerShopDatabaseImplement.Models;
using ComputerShopDataModels.Models;
using ComputerShopBusinessLogic.OfficePackage;
using ComputerShopBusinessLogic.OfficePackage.Implements;
using Microsoft.OpenApi.Models;
using ComputerShopContracts.BindingModels;
var Builder = WebApplication.CreateBuilder(args);
Builder.Logging.SetMinimumLevel(LogLevel.Trace);
Builder.Logging.AddLog4Net("log4net.config");
//!!!ÌÁ ÓÄÀËÈÒÜ
//Builder.Services.AddTransient<IOrderModel, Order>();
//Builder.Services.AddTransient<IShipmentModel, Shipment>();
//Builder.Services.AddTransient<IRequestModel, Request>();
Builder.Services.AddTransient<IUserStorage, UserStorage>();
Builder.Services.AddTransient<IShipmentStorage, ShipmentStorage>();
Builder.Services.AddTransient<IRequestStorage, RequestStorage>();
Builder.Services.AddTransient<IOrderStorage, OrderStorage>();
Builder.Services.AddTransient<IAssemblyStorage, AssemblyStorage>();
Builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
Builder.Services.AddTransient<IProductStorage, ProductStorage>();
Builder.Services.AddTransient<IUserLogic, UserLogic>();
Builder.Services.AddTransient<IShipmentLogic, ShipmentLogic>();
Builder.Services.AddTransient<IRequestLogic, RequestLogic>();
Builder.Services.AddTransient<IOrderLogic, OrderLogic>();
Builder.Services.AddTransient<IAssemblyLogic, AssemblyLogic>();
Builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
Builder.Services.AddTransient<IProductLogic, ProductLogic>();
Builder.Services.AddTransient<IReportImplementerLogic, ReportImplementerLogic>();
Builder.Services.AddTransient<IReportGuarantorLogic, ReportGuarantorLogic>();
Builder.Services.AddTransient<AbstractSaveToExcelImplementer, SaveToExcelImplementer>();
Builder.Services.AddTransient<AbstractSaveToWordImplementer, SaveToWordImplementer>();
Builder.Services.AddTransient<AbstractSaveToPdfImplementer, SaveToPdfImplementer>();
Builder.Services.AddTransient<AbstractSaveToExcelGuarantor, SaveToExcelGuarantor>();
Builder.Services.AddTransient<AbstractSaveToWordGuarantor, SaveToWordGuarantor>();
Builder.Services.AddTransient<AbstractSaveToPdfGuarantor, SaveToPdfGuarantor>();
Builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
Builder.Services.AddControllers();
Builder.Services.AddEndpointsApiExplorer();
Builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "ComputerShopRestApi",
Version = "v1"
});
});
var App = Builder.Build();
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())
});
if (App.Environment.IsDevelopment())
{
App.UseSwagger();
App.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ComputerShopRestApi v1"));
}
App.UseHttpsRedirection();
App.UseAuthorization();
App.MapControllers();
App.Run();