Files
JudoWeb/API/Program.cs

53 lines
1.2 KiB
C#

using API.Database;
using API.Repository.AgeGroup;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Database
var postgreConnection = builder.Configuration.GetConnectionString("PostgresConnection");
if (!string.IsNullOrEmpty(postgreConnection))
{
// Nutze PostgresSQL
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(postgreConnection));
}
else
{
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite("Data Source=app.db"));
}
// Adding Database Services
builder.Services.AddScoped<IAgeGroupService, AgeGroupService>();
// Adding S3 Services
// Adding (latler) Redis Services
// Add Database Services
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
using(var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
dbContext.Database.Migrate();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();