2023-09-27 11:31:46 +10:00
|
|
|
|
using Elastic.CommonSchema.Serilog;
|
2023-05-17 16:00:50 +10:00
|
|
|
|
using FluentValidation;
|
2023-12-04 10:56:29 +10:00
|
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
2023-12-01 16:41:37 +10:00
|
|
|
|
using PARR.API.Authentication;
|
2023-05-17 16:30:13 +10:00
|
|
|
|
using PARR.API.Installers;
|
2023-08-25 11:29:00 +10:00
|
|
|
|
using PARR.BLL;
|
2023-05-17 16:30:13 +10:00
|
|
|
|
using PARR.DAL;
|
2023-05-17 16:00:50 +10:00
|
|
|
|
using Serilog;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
2023-05-17 15:17:00 +10:00
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
2023-05-17 16:00:50 +10:00
|
|
|
|
builder.Host.UseSerilog((context, config) =>
|
|
|
|
|
|
{
|
2023-09-27 11:31:46 +10:00
|
|
|
|
if (context.HostingEnvironment.IsProduction())
|
|
|
|
|
|
config.WriteTo.Console(new EcsTextFormatter());
|
|
|
|
|
|
else
|
|
|
|
|
|
config.WriteTo.Console();
|
|
|
|
|
|
|
|
|
|
|
|
config.ReadFrom.Configuration(builder.Configuration);
|
2023-05-17 16:00:50 +10:00
|
|
|
|
});
|
|
|
|
|
|
|
2023-05-17 15:17:00 +10:00
|
|
|
|
// Add services to the container.
|
2023-05-17 16:30:13 +10:00
|
|
|
|
builder.Services.InstallDalServices(builder.Configuration);
|
2023-08-25 11:29:00 +10:00
|
|
|
|
builder.Services.InstallBllServices(builder.Configuration);
|
2023-05-17 16:00:50 +10:00
|
|
|
|
builder.Services.InstallApiServices(builder.Configuration);
|
|
|
|
|
|
builder.Services.InstallSettings(builder.Configuration);
|
|
|
|
|
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
|
|
|
|
|
|
2023-09-19 14:34:55 +10:00
|
|
|
|
// Dal configuration
|
|
|
|
|
|
builder.Configuration.AddDalConfigurations(builder.Services);
|
|
|
|
|
|
builder.Services.AddDallSettings(builder.Configuration);
|
|
|
|
|
|
|
2023-12-01 16:41:37 +10:00
|
|
|
|
// Auth
|
2023-12-04 12:02:55 +10:00
|
|
|
|
builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme)
|
|
|
|
|
|
.AddScheme<ParrAuthenticationOptions, ParrAuthenticationHandler>(ParrAuthenticationOptions.DefaultScheme, opt => { });
|
2023-12-04 08:48:13 +10:00
|
|
|
|
// не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler
|
|
|
|
|
|
//builder.Services.AddSimpleRoleAuthorization<BaseSimpleRoleProvider>();
|
2023-12-01 16:41:37 +10:00
|
|
|
|
|
2023-12-04 12:02:55 +10:00
|
|
|
|
// При использовании балансировщика (haproxy, перенаправлять заголовки) (см ниже: app.UseForwardedHeaders();)
|
|
|
|
|
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
2023-12-04 10:56:29 +10:00
|
|
|
|
|
2023-12-04 12:02:55 +10:00
|
|
|
|
options.KnownNetworks.Clear();
|
|
|
|
|
|
options.KnownProxies.Clear();
|
|
|
|
|
|
});
|
2023-12-04 10:56:29 +10:00
|
|
|
|
|
2023-12-01 16:41:37 +10:00
|
|
|
|
|
2023-05-17 16:00:50 +10:00
|
|
|
|
builder.Services.AddHttpContextAccessor();
|
2023-05-17 15:17:00 +10:00
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
2023-05-17 16:00:50 +10:00
|
|
|
|
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
|
|
|
2023-05-17 15:17:00 +10:00
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
2023-05-17 16:00:50 +10:00
|
|
|
|
builder.Services.InstallSwaggerService(builder.Configuration);
|
|
|
|
|
|
|
2023-05-17 15:17:00 +10:00
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
2023-12-04 12:02:55 +10:00
|
|
|
|
// При использовании балансировщика (haproxy, перенаправлять заголовки)
|
|
|
|
|
|
app.UseForwardedHeaders();
|
|
|
|
|
|
|
2023-05-17 15:17:00 +10:00
|
|
|
|
// Configure the HTTP request pipeline.
|
2023-05-17 16:00:50 +10:00
|
|
|
|
app.InstallSwagger();
|
2023-05-17 15:17:00 +10:00
|
|
|
|
|
2023-12-01 16:41:37 +10:00
|
|
|
|
app.UseAuthentication();
|
2023-05-17 15:17:00 +10:00
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
|
|
|
|
app.Run();
|