Use in-memory runtime state with SQLite write-through

This commit is contained in:
2026-02-24 23:13:20 +01:00
parent f212636feb
commit 5c199b4468
4 changed files with 743 additions and 455 deletions

View File

@@ -14,16 +14,18 @@ var sqliteConnectionString = builder.Configuration.GetConnectionString("RpgRolle
EnsureSqliteDataDirectory(sqliteConnectionString, builder.Environment.ContentRootPath);
builder.Services.AddSingleton<IPasswordHasher<UserAccount>, PasswordHasher<UserAccount>>();
builder.Services.AddDbContext<RpgRollerDbContext>(options => options.UseSqlite(sqliteConnectionString));
builder.Services.AddDbContextFactory<RpgRollerDbContext>(options => options.UseSqlite(sqliteConnectionString));
builder.Services.AddSingleton<IDiceRoller, RandomDiceRoller>();
builder.Services.AddScoped<IGameService, GameService>();
builder.Services.AddSingleton<IGameService, GameService>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<RpgRollerDbContext>();
var dbFactory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<RpgRollerDbContext>>();
using var db = dbFactory.CreateDbContext();
db.Database.EnsureCreated();
_ = scope.ServiceProvider.GetRequiredService<IGameService>();
}
app.UseDefaultFiles();

File diff suppressed because it is too large Load Diff