Added instrastructure extensions

Implemented database service registration
This commit is contained in:
2026-08-16 10:33:12 +02:00
parent a9f4b45d20
commit def73c3fa8
4 changed files with 29 additions and 3 deletions
@@ -0,0 +1,6 @@
namespace PostFundManagement.Infrastructure.Extensions;
public static class Constants
{
public const string DatabaseConfigName = "PfmDatabase";
}
@@ -0,0 +1,17 @@
using PostFundManagement.Infrastructure.Database;
using static PostFundManagement.Infrastructure.Extensions.Constants;
namespace PostFundManagement.Infrastructure.Extensions;
public static class Postgres
{
public static IServiceCollection AddApplicationDbContext(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(DatabaseConfigName)
?? throw new InvalidOperationException($"Connection string '{DatabaseConfigName}' was not found in configuration.");
services.AddPooledDbContextFactory<ApplicationDbContext>(builder => builder.UseNpgsql(connectionString));
return services;
}
}