using DigitalData.Core.Application.Interfaces.Repository;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace DigitalData.Core.Infrastructure;

public static class DependencyInjection
{
    public static EntityConfigurationOptions<TEntity> AddDbRepository<TDbContext, TEntity>(this IServiceCollection services, Func<TDbContext, DbSet<TEntity>> queryFactory)
        where TDbContext : DbContext
        where TEntity : class
    {
        services
            .AddScoped<IRepository<TEntity>, DbRepository<TDbContext, TEntity>>()
            .AddSingleton(queryFactory);

        return new EntityConfigurationOptions<TEntity>(services);
    }
}