using System.Reflection; using System.Text.Json.Serialization; using Abstractions; using HashidsNet; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Security; using Security.Scheme; using W542.GandalfReborn.Data.Database; using W542.GandalfReborn.Data.Database.Repositories; var builder = WebApplication.CreateBuilder(args); builder.Services.AddSingleton(TimeProvider.System); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddDbContext(cfg => cfg .UseNpgsql( builder.Configuration.GetConnectionString("DefaultConnection"), x => x.MigrationsAssembly("Data") ) ); builder.Services.AddAutoMapper(typeof(ApplicationContext).Assembly); builder.Services.Configure(opt => { opt.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3; opt.IterationCount = 210_000; }); builder.Services.AddSingleton>(new PasswordHasher()); builder.Services.AddScoped(); builder.Services.AddSingleton(new Hashids(builder.Configuration.GetValue("HashIdSalt") ?? "superSalt", 12)); builder.Services.AddGandalfRebornJwtTokenAuth(options => { options.JwtSecret = builder.Configuration.GetValue("JwtSecret") ?? "superSecret"; options.BaseUrl = builder.Configuration.GetValue("BaseUrl") ?? ""; }); builder.Services.AddSingleton(); builder.Services.AddRouting(options => options.LowercaseUrls = true); builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddMediatR(config => { config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); }); builder.Services.AddOpenApi(); var app = builder.Build(); var scope = app.Services.CreateScope(); var applicationContext = scope.ServiceProvider.GetRequiredService(); applicationContext.Database.EnsureCreated(); applicationContext.AddVersionTriggers(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } app.UseHttpsRedirection(); app.MapControllers(); app.Run();