using HopFrame.Core.Config; using HopFrame.Web; using Microsoft.EntityFrameworkCore; using Portfolio.Api; using Portfolio.Api.Services; using Portfolio.Shared.Models; using Portfolio.Shared.Services; var builder = WebApplication.CreateBuilder(args); // Add services to the container. // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); builder.AddServiceDefaults(); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); builder.AddNpgsqlDbContext("data"); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddControllers(); builder.Services.AddHopFrame(options => { options.DisplayUserInfo(false); options.AddDbContext(context => { context.Table(table => { var langConfig = table.InnerConfig.Properties .Single(prop => prop.Name == nameof(Project.Languages)); langConfig .GetType()! .GetProperty(nameof(PropertyConfig.IsRelation))! .SetValue(langConfig, true); langConfig .GetType()! .GetProperty(nameof(PropertyConfig.IsEnumerable))! .SetValue(langConfig, true); langConfig .GetType()! .GetProperty(nameof(PropertyConfig.IsRequired))! .SetValue(langConfig, true); table.Property(p => p.Languages) .FormatEach((l, _) => l.Name) .List(false); table.Property(p => p.Cover) .List(false); table.Property(p => p.Description) .List(false) .IsTextArea(true); table.Property(p => p.SourceCode) .List(false); }); context.Table(table => { table.Property(a => a.AboutMe) .List(false) .IsTextArea(true); table.Property(a => a.Future) .List(false) .IsTextArea(true); }); context.Table(table => { table.Property(t => t.Description) .IsTextArea(true) .List(false); }); }); }); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } await using (var scope = app.Services.CreateAsyncScope()) { var db = scope.ServiceProvider.GetRequiredService(); await db.Database.EnsureCreatedAsync(); } app.MapDefaultEndpoints(); app.MapControllers(); app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .MapHopFramePages(); app.Run();