feat(IRepositoryFactory): create to capsulate repository geenration.

- update DbRepo to use IRepositoryFactory
This commit is contained in:
tekh 2025-09-10 17:48:16 +02:00
parent 7d3d3b5ae9
commit 272650d991
2 changed files with 10 additions and 4 deletions

View File

@ -0,0 +1,6 @@
namespace DigitalData.Core.Abstraction.Application.Repository;
public interface IRepositoryFactory
{
public IRepository<TEntity> Get<TEntity>();
}

View File

@ -79,12 +79,12 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
public class DbRepository : IRepository
{
private readonly IServiceProvider _provider;
private readonly IRepositoryFactory _factory;
public DbRepository(IServiceProvider provider)
public DbRepository(IRepositoryFactory factory)
{
_provider = provider;
_factory = factory;
}
public IRepository<TEntity> Entity<TEntity>() => _provider.GetRequiredService<IRepository<TEntity>>();
public IRepository<TEntity> Entity<TEntity>() => _factory.Get<TEntity>();
}