Use in-memory runtime state with SQLite write-through
This commit is contained in:
@@ -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
Reference in New Issue
Block a user