73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
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<ApplicationContext>(cfg => cfg
|
|
.UseNpgsql(
|
|
builder.Configuration.GetConnectionString("DefaultConnection"),
|
|
x => x.MigrationsAssembly("Data")
|
|
)
|
|
);
|
|
|
|
builder.Services.AddAutoMapper(typeof(ApplicationContext).Assembly);
|
|
|
|
builder.Services.Configure<PasswordHasherOptions>(opt =>
|
|
{
|
|
opt.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3;
|
|
opt.IterationCount = 210_000;
|
|
});
|
|
builder.Services.AddSingleton<IPasswordHasher<object>>(new PasswordHasher<object>());
|
|
builder.Services.AddScoped<InvokerContext>();
|
|
|
|
builder.Services.AddSingleton<IHashids>(new Hashids(builder.Configuration.GetValue<string>("HashIdSalt") ?? "superSalt", 12));
|
|
builder.Services.AddGandalfRebornJwtTokenAuth(options =>
|
|
{
|
|
options.JwtSecret = builder.Configuration.GetValue<string>("JwtSecret") ?? "superSecret";
|
|
options.BaseUrl = builder.Configuration.GetValue<string>("BaseUrl") ?? "";
|
|
});
|
|
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
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<ISubjectRepository, SubjectRepository>();
|
|
builder.Services.AddScoped<IAuthCodeRepository, AuthCodeRepository>();
|
|
builder.Services.AddScoped<ITokenMetadataRepository, TokenMetadataRepository>();
|
|
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>();
|
|
applicationContext.Database.EnsureCreated();
|
|
applicationContext.AddVersionTriggers();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.MapControllers();
|
|
|
|
app.Run(); |