PIbd-21_Pyatakov_KM_Markov_.../UniversityRestAPI/Program.cs

70 lines
2.8 KiB
C#

using UniversityBusinessLogic.BusinessLogic.OfficePackage;
using Microsoft.OpenApi.Models;
using System.Reflection.PortableExecutable;
using UniversityBusinessLogic.BusinessLogics;
using UniversityBusinessLogic.OfficePackage;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.StoragesContracts;
using UniversityDataBaseImplemet.Implements;
using UniversityContracts.BindingModels;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IStudentStorage, StudentStorage>();
builder.Services.AddTransient<IEducationStatusStorage, EducationStatusStorage>();
builder.Services.AddTransient<IDocumentStorage, DocumentStorage>();
builder.Services.AddTransient<IEducationGroupStorage, EducationGroupStorage>();
builder.Services.AddTransient<IDisciplineStorage, DisciplineStorage>();
builder.Services.AddTransient<IStreamStorage, StreamStorage>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IStudentLogic, StudentLogic>();
builder.Services.AddTransient<IEducationStatusLogic, EducationStatusLogic>();
builder.Services.AddTransient<IDocumentLogic, DocumentLogic>();
builder.Services.AddTransient<IEducationGroupLogic, EducationGroupLogic>();
builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>();
builder.Services.AddTransient<IStreamLogic, StreamLogic>();
builder.Services.AddTransient<IReportProviderLogic, ReportProviderLogic>();
builder.Services.AddTransient<WordBuilderProvider>();
builder.Services.AddTransient<ExcelBuilderProvider>();
builder.Services.AddTransient<PdfBuilderProvider>();
builder.Services.AddSingleton<MailSender>();
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 = "UniversityRestApi", Version = "v1" });
});
var app = builder.Build();
var mailSender = app.Services.GetService<MailSender>();
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()),
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "UniversityRestApi"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();