Files
GerbilManager/GerbilManagerWebAPI/Program.cs
2026-06-05 23:37:42 +02:00

42 lines
1.0 KiB
C#

using GerbilManagerWebAPI.DAL;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.AddNpgsqlDbContext<ApplicationContext>("gerbilmanager");
builder.Services.AddScoped<UnitOfWork>();
var app = builder.Build();
app.MapDefaultEndpoints();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
// Aspire provisions an empty database in dev — bring the schema up to date.
using var scope = app.Services.CreateScope();
scope.ServiceProvider.GetRequiredService<ApplicationContext>().Database.Migrate();
}
if (app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
app.UseAuthorization();
app.MapControllers();
app.Run();