using DbFirst.Application.Repositories;
using DbFirst.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace DbFirst.Infrastructure;

public static class DependencyInjection
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {
        services.Configure<TableConfigurations>(configuration.GetSection("TableConfigurations"));
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));

        services.AddDbContext<MassDataDbContext>(options =>
            options.UseSqlServer(configuration.GetConnectionString("MassDataConnection")));

        services.AddScoped<ICatalogRepository, CatalogRepository>();
        services.AddScoped<IMassDataRepository, MassDataRepository>();
        services.AddScoped<ILayoutRepository, LayoutRepository>();

        return services;
    }
}
