CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs

90 lines
3.6 KiB
C#

using BankYouBankruptBusinessLogic.BusinessLogics;
using BankYouBankruptBusinessLogic.MailWorker;
using BankYouBankruptBusinessLogic.OfficePackage;
using BankYouBankruptBusinessLogic.OfficePackage.Implements;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptDatabaseImplement.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<IClientStorage, ClientStorage>();
builder.Services.AddTransient<ICashierStorage, CashierStorage>();
builder.Services.AddTransient<IAccountStorage, AccountStorage>();
builder.Services.AddTransient<ICardStorage, CardStorage>();
builder.Services.AddTransient<ICreditingStorage, CreditingStorage>();
builder.Services.AddTransient<IMoneyTransferStorage, MoneyTransferStorage>();
builder.Services.AddTransient<IDebitingStorage, DebitingStorage>();
builder.Services.AddTransient<ICashWithdrawalStorage, CashWithdrawalStorage>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ICashierLogic, CashierLogic>();
builder.Services.AddTransient<IAccountLogic, AccountLogic>();
builder.Services.AddTransient<ICardLogic, CardLogic>();
builder.Services.AddTransient<ICreditingLogic, CreditingLogic>();
builder.Services.AddTransient<IMoneyTransferLogic, MoneyTransferLogic>();
builder.Services.AddTransient<IDebitingLogic, DebitingLogic>();
builder.Services.AddTransient<ICashWithdrawalLogic, CashWithdrawalLogic>();
builder.Services.AddTransient<IReportClientLogic, ReportClientLogic>();
builder.Services.AddSingleton<IReportCashierLogic, ReportCashierLogic>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
//общие классы формировани отчётов
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToWordClient, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToWordCashier, SaveToWordCashier>();
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 = "BankYouBankruptRestAPI", Version = "v1" });
});
var app = builder.Build();
//Mails Service
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())
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BankYouBankruptRestAPI v1"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();