using BusinessLogic.BusinessLogic; using BusinessLogic.Tools; using BusinessLogic.Tools.Mail; using Contracts.BusinessLogicContracts; using Contracts.StorageContracts; using DatabaseImplement.Implements; using Microsoft.OpenApi.Models; using System; using System.Net.Mail; const string VERSION = "v1"; const string TITLE = "21GunsRestAPI"; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.AddLog4Net("log4net.config"); #region DI builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); #endregion DI builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc(VERSION, new OpenApiInfo { Title = TITLE, Version = VERSION }); }); var app = builder.Build(); var jwtProvider = app.Services.GetService(); var mailSender = app.Services.GetService(); #region Setup config string? getSection(string section) => builder.Configuration?.GetSection(section)?.Value?.ToString(); jwtProvider?.SetupJwtOptions(new() { SecretKey = getSection("JwtOptions:SecretKey") ?? string.Empty, ExpiresHours = Convert.ToInt16(getSection("JwtOptions:ExpiresHours")) }); mailSender?.SetupMailOptions(new() { Email = getSection("MailOptions:Email") ?? string.Empty, Password = getSection("MailOptions:Password") ?? string.Empty, SmtpClientHost = getSection("MailOptions:SmtpClientHost") ?? string.Empty, SmtpClientPort = Convert.ToInt16(getSection("MailOptions:SmtpClientPort")) }); #endregion Setup config System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint($"/swagger/{VERSION}/swagger.json", $"{TITLE} {VERSION}")); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.UseDeveloperExceptionPage(); app.Run();