PIbd-22_Filippov_D.S._Cours.../VeterinaryRestApi/Program.cs
2024-05-30 07:33:38 +04:00

84 lines
3.3 KiB
C#

using VeterinaryBusinessLogic.BusinessLogic;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.StorageContracts;
using VeterinaryDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
using VeterinaryBusinessLogic.MailWorker;
using VeterinaryBusinessLogic.OfficePackage;
using VeterinaryBusinessLogic.OfficePackage.Implements;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddTransient<IDoctorStorage, DoctorStorage>();
builder.Services.AddTransient<IPetStorage, PetStorage>();
builder.Services.AddTransient<IDrugStorage, DrugStorage>();
builder.Services.AddTransient<IVisitStorage, VisitStorage>();
builder.Services.AddTransient<IOwnerStorage, OwnerStorage>();
builder.Services.AddTransient<IServiceStorage, ServiceStorage>();
builder.Services.AddTransient<IMedicationStorage, MedicationStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IDoctorLogic, DoctorLogic>();
builder.Services.AddTransient<IPetLogic, PetLogic>();
builder.Services.AddTransient<IDrugLogic, DrugLogic>();
builder.Services.AddTransient<IVisitLogic, VisitLogic>();
builder.Services.AddTransient<IOwnerLogic, OwnerLogic>();
builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
builder.Services.AddTransient<IMedicationLogic, MedicationLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddTransient<IReportLogicDoctor, ReportLogicDoctor>();
builder.Services.AddTransient<IReportLogicOwner, ReportLogicOwner>();
builder.Services.AddTransient<AbstractSaveToExcelDoctor, SaveToExcelDoctor>();
builder.Services.AddTransient<AbstractSaveToWordDoctor, SaveToWordDoctor>();
builder.Services.AddTransient<AbstractSaveToPdfDoctor, SaveToPdfDoctor>();
builder.Services.AddTransient<AbstractSaveToExcelOwner, SaveToExcelOwner>();
builder.Services.AddTransient<AbstractSaveToWordOwner, SaveToWordOwner>();
builder.Services.AddTransient<AbstractSaveToPdfOwner, SaveToPdfOwner>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
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 = "VeterinaryViewRestApi", 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())
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();