23 lines
721 B
C#
23 lines
721 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.IO;
|
|
namespace UtopiaCanteenSystem.Data;
|
|
|
|
/// <summary>
|
|
/// Factory for creating AppDbContext instances. Used by RfidService and SyncService
|
|
/// to avoid sharing a single context across async operations.
|
|
/// </summary>
|
|
public class DbContextFactory : IDbContextFactory<AppDbContext>
|
|
{
|
|
private static readonly DbContextOptions<AppDbContext> Options;
|
|
|
|
static DbContextFactory()
|
|
{
|
|
var builder = new DbContextOptionsBuilder<AppDbContext>();
|
|
var dbPath = DatabasePath.GetDbPath();
|
|
builder.UseSqlite($"Data Source={dbPath}");
|
|
Options = builder.Options;
|
|
}
|
|
|
|
public AppDbContext CreateDbContext() => new AppDbContext(Options);
|
|
}
|