InkForge/app/InkForge.Desktop/Data/NoteDbContextFactory.cs

28 lines
743 B
C#
Raw Permalink Normal View History

2024-02-16 02:23:58 +01:00
using InkForge.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using SmartFormat;
using InkForge.Desktop.Data.Options;
2024-02-16 02:23:58 +01:00
namespace InkForge.Desktop.Data;
public class NoteDbContextFactory(LocalWorkspaceOptions options, IConfiguration configuration) : IDbContextFactory<NoteDbContext>
2024-02-16 02:23:58 +01:00
{
private string? _connectionString;
public NoteDbContext CreateDbContext()
{
_connectionString ??= Smart.Format(configuration.GetConnectionString("DefaultConnection")!, new
{
WorkspaceFile = options.DbPath
2024-02-16 02:23:58 +01:00
});
DbContextOptionsBuilder<NoteDbContext> builder = new();
builder.UseSqlite(_connectionString, o => o.MigrationsAssembly("InkForge.Sqlite"));
return new NoteDbContext(builder.Options);
}
}