PIbd-22_Karamushko_M_K_Pizz.../Pizzeria/PizzeriaRestApi/Program.cs

58 lines
2.5 KiB
C#
Raw Permalink Normal View History

2023-03-28 08:52:39 +04:00
using PizzeriaBusinessLogic;
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.StoragesContracts;
using PizzeriaDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
2023-04-22 18:57:09 +04:00
using PizzeriaBusinessLogic.MailWorker;
using PizzeriaContracts.BindingModels;
2023-03-27 23:45:20 +04:00
2023-03-28 08:52:39 +04:00
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
2023-03-27 23:45:20 +04:00
// Add services to the container.
2023-03-28 08:52:39 +04:00
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<IPizzaStorage, PizzaStorage>();
2023-04-11 09:29:12 +04:00
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
2023-05-02 22:25:20 +04:00
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
2023-03-28 08:52:39 +04:00
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
2023-04-11 09:29:12 +04:00
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
2023-03-28 08:52:39 +04:00
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IPizzaLogic, PizzaLogic>();
2023-05-02 22:25:20 +04:00
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
2023-03-27 23:45:20 +04:00
builder.Services.AddControllers();
2023-03-28 08:52:39 +04:00
// Learn more about configuring Swagger/OpenAPI at
https://aka.ms/aspnetcore/swashbuckle
2023-03-27 23:45:20 +04:00
builder.Services.AddEndpointsApiExplorer();
2023-03-28 08:52:39 +04:00
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
2023-05-02 22:25:20 +04:00
Title = "PizzeriaRestApi",
Version = "v1"
2023-03-28 08:52:39 +04:00
});
});
2023-03-27 23:45:20 +04:00
var app = builder.Build();
2023-04-22 18:57:09 +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-03-27 23:45:20 +04:00
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
2023-05-02 22:25:20 +04:00
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1"));
2023-03-27 23:45:20 +04:00
}
app.UseAuthorization();
app.MapControllers();
app.Run();
2023-03-28 08:52:39 +04:00