using Microsoft.Extensions.DependencyInjection;
using OAService.Infrastructure.DAL.Repository;
using StandManager.Domain.Entita;
using StandManager.Infrastructure.DAL.Context;

namespace StandManager.Service.Repository;

public class StandManagerUnitOfWork : UnitOfWork, IStandManagerUnitOfWork
{
    private readonly StandManagerDbContext _context;
    private readonly IServiceProvider _provider;

    public StandManagerUnitOfWork(StandManagerDbContext context, IServiceProvider provider) : base(context, provider)
    {
        _context = context;
        _provider = provider;
    }

    public override IStandManagerGenericRepository<TEntity> GetRepository<TEntity>() where TEntity : class
    {
        return _provider.GetRequiredService<IStandManagerGenericRepository<TEntity>>();
    }
    
    
    private IStandManagerGenericRepository<Utente> _utenteRepository;
    public new IStandManagerGenericRepository<Utente> UtenteRepository => _utenteRepository ??= new StandManagerGenericRepository<Utente>(_context);
}