Add persisted runtime settings page with cookie login
This commit is contained in:
1 parent
b561924efa
commit
37987a394a
43 files changed
+1346
-61
No files matched your search
@@ -1,11 +1,26 @@
|
||||
using Flypaper.Core;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Flypaper.Storage;
|
||||
|
||||
public static class FlypaperStorageExtensions
|
||||
{
|
||||
public static IHostApplicationBuilder AddFlypaperStorage(this IHostApplicationBuilder builder)
|
||||
{
|
||||
var connectionString = builder.Configuration.GetConnectionString("Flypaper") ?? "Data Source=flypaper.db";
|
||||
|
||||
var source = new DbConfigurationSource(connectionString);
|
||||
builder.Configuration.Add(source);
|
||||
builder.Services.AddSingleton(source);
|
||||
builder.Services.AddSingleton<RuntimeSettingsStore>();
|
||||
builder.Services.AddFlypaperStorage(connectionString);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddFlypaperStorage(this IServiceCollection services, string connectionString)
|
||||
{
|
||||
services.AddDbContextFactory<FlypaperDbContext>(options => options.UseSqlite(connectionString));
|
||||
@@ -19,7 +34,11 @@ public static class FlypaperStorageExtensions
|
||||
public static async Task MigrateFlypaperDatabaseAsync(this IServiceProvider services, CancellationToken ct = default)
|
||||
{
|
||||
var factory = services.GetRequiredService<IDbContextFactory<FlypaperDbContext>>();
|
||||
await using var db = await factory.CreateDbContextAsync(ct);
|
||||
await db.Database.MigrateAsync(ct);
|
||||
await using (var db = await factory.CreateDbContextAsync(ct))
|
||||
{
|
||||
await db.Database.MigrateAsync(ct);
|
||||
}
|
||||
|
||||
services.GetService<DbConfigurationSource>()?.Reload();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user