From df7ba866f5adfe7342ee1a92f80763b112829665 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 15 Aug 2026 19:18:17 +0200 Subject: [PATCH] Added dbcontext factory --- .../Database/ApplicationDbContextFactory.cs | 22 +++++++++++++++++++ .../IInfrastructure.cs | 3 +++ .../PostFundManagement.Infrastructure.csproj | 13 +++++++++++ 3 files changed, 38 insertions(+) create mode 100644 PostFundManagement.Infrastructure/Database/ApplicationDbContextFactory.cs create mode 100644 PostFundManagement.Infrastructure/IInfrastructure.cs diff --git a/PostFundManagement.Infrastructure/Database/ApplicationDbContextFactory.cs b/PostFundManagement.Infrastructure/Database/ApplicationDbContextFactory.cs new file mode 100644 index 0000000..f3f27d7 --- /dev/null +++ b/PostFundManagement.Infrastructure/Database/ApplicationDbContextFactory.cs @@ -0,0 +1,22 @@ +namespace PostFundManagement.Infrastructure.Database; + +public sealed class ApplicationDbContextFactory : IDesignTimeDbContextFactory +{ + public ApplicationDbContext CreateDbContext(string[] args) + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddUserSecrets(optional: true) + .AddEnvironmentVariables() + .Build(); + + var optionsBuilder = new DbContextOptionsBuilder(); + + var connectionString = configuration.GetConnectionString("PfmDatabase") + ?? throw new InvalidOperationException("Connection string 'PfmDatabase' was not found in configuration."); + + optionsBuilder.UseNpgsql(connectionString, npgsqlOptions => npgsqlOptions.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)); + + return new ApplicationDbContext(optionsBuilder.Options); + } +} \ No newline at end of file diff --git a/PostFundManagement.Infrastructure/IInfrastructure.cs b/PostFundManagement.Infrastructure/IInfrastructure.cs new file mode 100644 index 0000000..6795a51 --- /dev/null +++ b/PostFundManagement.Infrastructure/IInfrastructure.cs @@ -0,0 +1,3 @@ +namespace PostFundManagement.Infrastructure; + +public interface IInfrastructure; \ No newline at end of file diff --git a/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj b/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj index 694b6af..4895080 100644 --- a/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj +++ b/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj @@ -4,10 +4,23 @@ net10.0 enable enable + c4131f8d-ff78-432e-86d2-f6e131bd4cd3 + + + + + + + + + + + +