blob: 0fefe4658074e288d044f0a48c9d007e5092610f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using Microsoft.EntityFrameworkCore;
using WikiWaka.Api.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddHealthChecks();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DbWikiWakaContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DbWikiWaka")));
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapControllers();
app.MapHealthChecks("/healthz");
using (var scope = app.Services.CreateScope())
{
await using DbWikiWakaContext db = scope.ServiceProvider.GetRequiredService<DbWikiWakaContext>();
ILogger<Program> logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
bool isNewDatabase = await db.Database.EnsureCreatedAsync();
if (isNewDatabase)
{
logger.LogInformation("Creating new database...");
await DbInit.InitializeLanguages(db);
}
else
logger.LogInformation("Database existed before, not changing");
}
app.Run();
|