using CalledIt.Util;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CalledIt.DataAccess;

public class DataAccessModule : DependencyInjectionModule
{
    protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        string connectionString = configuration.GetConnectionString("DefaultConnection")
            ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");

        services.AddDbContextPool<CalledItDbContext>(options =>
            options.UseNpgsql(connectionString));
    }
}
