Files
jsmr/JSMR.Infrastructure/Data/AppDbContextFactory.cs
Brian Bicknell a85989a337
Some checks failed
ci / build-test (push) Has been cancelled
ci / publish-image (push) Has been cancelled
Fixed scanning issue. Updated worker.
2026-02-14 22:47:19 -05:00

30 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace JSMR.Infrastructure.Data;
public sealed class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
// adjust base path if needed (points to the worker for secrets/env)
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile("appsettings.Development.json", optional: true)
.AddUserSecrets(typeof(AppDbContextFactory).Assembly, optional: true)
.AddEnvironmentVariables()
.Build();
var conn = config.GetConnectionString("AppDb")
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseMySql(conn, ServerVersion.AutoDetect(conn))
.EnableSensitiveDataLogging(false)
.Options;
return new AppDbContext(options);
}
}