CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopRestAPI/Program.cs

108 lines
4.1 KiB
C#
Raw Normal View History

2024-05-27 14:57:41 +04:00
using ElectronicsShopBusinessLogic.BusinessLogic;
2024-06-01 05:27:52 +04:00
using ElectronicsShopBusinessLogic.MailWorker;
using ElectronicsShopBusinessLogic.OfficePackage;
using ElectronicsShopBusinessLogic.OfficePackage.Implements;
using ElectronicsShopContracts.BindingModels;
2024-05-27 14:57:41 +04:00
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopDataBaseImplement.Implements;
2024-04-29 21:57:01 +04:00
using Microsoft.OpenApi.Models;
2024-06-01 05:27:52 +04:00
using Serilog;
2024-04-29 21:57:01 +04:00
2024-04-29 21:38:18 +04:00
var builder = WebApplication.CreateBuilder(args);
//todo logger!!!
2024-06-01 05:27:52 +04:00
builder.Services.AddControllersWithViews();
builder.Services.AddSession(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-04-29 21:38:18 +04:00
// Add services to the container.
2024-05-27 14:57:41 +04:00
builder.Services.AddTransient<IClientStorage, ClientStorage>();
2024-05-27 17:35:14 +04:00
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
2024-05-27 18:06:34 +04:00
builder.Services.AddTransient<IProductStorage, ProductStorage>();
2024-05-27 18:36:13 +04:00
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
2024-06-01 05:27:52 +04:00
builder.Services.AddTransient<IPaymeantStorage, PaymeantStorage>();
2024-05-27 22:05:47 +04:00
builder.Services.AddTransient<ICostItemStorage, CostItemStorage>();
2024-06-01 05:00:05 +04:00
builder.Services.AddTransient<IPaymeantStorage, PaymeantStorage>();
2024-05-27 14:57:41 +04:00
2024-06-01 05:27:52 +04:00
builder.Services.AddTransient<AbstractSaveToExcelClient, SaveToExcelClient>();
builder.Services.AddTransient<AbstractSaveToExcelEmployee, SaveToExcelEmployee>();
builder.Services.AddTransient<AbstractSaveToWordClient, SaveToWordClient>();
builder.Services.AddTransient<AbstractSaveToWordEmployee, SaveToWordEmployee>();
2024-07-23 20:29:10 +04:00
builder.Services.AddTransient<AbstractSaveToPdfClient, SaveToPdfClient>();
2024-06-01 05:27:52 +04:00
2024-05-27 14:57:41 +04:00
builder.Services.AddTransient<IClientLogic, ClientLogic>();
2024-05-27 17:35:14 +04:00
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
2024-05-27 18:06:34 +04:00
builder.Services.AddTransient<IProductLogic, ProductLogic>();
2024-05-27 18:36:13 +04:00
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
2024-05-27 22:05:47 +04:00
builder.Services.AddTransient<ICostItemLogic, CostItemLogic>();
2024-06-01 05:27:52 +04:00
builder.Services.AddTransient<IReportClientLogic, ReportClientLogic>();
builder.Services.AddTransient<IReportEmployeeLogic, ReportEmployeeLogic>();
builder.Services.AddTransient<IPaymeantLogic, PaymeantLogic>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.AddSerilog(logger);
});
2024-05-27 14:57:41 +04:00
2024-04-29 21:38:18 +04:00
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
2024-06-01 05:27:52 +04:00
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "JurasicZooRestApi",
Version = "v1"
});
});
2024-04-29 21:38:18 +04:00
var app = builder.Build();
2024-06-01 05:27:52 +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())
});
2024-04-29 21:38:18 +04:00
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
2024-06-01 05:27:52 +04:00
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "JurasicZooRestApi v1"));
2024-04-29 21:38:18 +04:00
}
app.UseHttpsRedirection();
2024-06-01 05:27:52 +04:00
app.UseRouting();
app.UseStaticFiles();
app.UseSession(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
app.UseRouting();
2024-04-29 21:38:18 +04:00
app.UseAuthorization();
2024-06-01 05:27:52 +04:00
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
2024-04-29 21:38:18 +04:00
app.Run();