61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System.Text.Json;
|
|
using DysonNetwork.Pass;
|
|
using DysonNetwork.Pass.Localization;
|
|
using DysonNetwork.Pass.Startup;
|
|
using DysonNetwork.Shared.Etcd;
|
|
using DysonNetwork.Shared.Startup;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NodaTime;
|
|
using NodaTime.Serialization.SystemTextJson;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.ConfigureAppKestrel();
|
|
builder.Services.AddHttpClient();
|
|
|
|
builder.Services.AddControllers().AddJsonOptions(options =>
|
|
{
|
|
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
|
|
options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.SnakeCaseLower;
|
|
|
|
options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
|
}).AddDataAnnotationsLocalization(options =>
|
|
{
|
|
options.DataAnnotationLocalizerProvider = (type, factory) =>
|
|
factory.Create(typeof(SharedResource));
|
|
});
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddAppSwagger();
|
|
builder.Services.AddAppAuthentication();
|
|
builder.Services.AddAppRateLimiting();
|
|
|
|
builder.Services.AddMagicOnion();
|
|
builder.Services.AddEtcdService(builder.Configuration);
|
|
|
|
builder.Services.AddAppBusinessServices(builder.Configuration);
|
|
builder.Services.AddAppServices(builder.Configuration);
|
|
|
|
builder.Services.AddDbContext<AppDatabase>(options =>
|
|
options.UseNpgsql(builder.Configuration.GetConnectionString("App")));
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
app.UseStaticFiles();
|
|
app.UseAuthorization();
|
|
app.ConfigureAppMiddleware(builder.Configuration);
|
|
|
|
app.MapControllers();
|
|
app.MapMagicOnionService();
|
|
|
|
// Run database migrations
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
|
await db.Database.MigrateAsync();
|
|
}
|
|
|
|
app.Run(); |