Refactor repository pattern and dependency injection

This commit introduces a new `DbRepository` class implementing the `IRepository<TEntity>` interface, providing asynchronous methods for CRUD operations. The previous CRUD repository registration in `DIExtensions.cs` has been removed, indicating a shift in repository management. A new static class `DependencyInjection` has been added to facilitate the registration of `DbRepository` with the service collection, enhancing modularity and flexibility in database interactions.
This commit is contained in:
Developer 02
2025-04-16 09:12:06 +02:00
parent 162da9a16c
commit 72603f836c
3 changed files with 60 additions and 28 deletions

View File

@@ -0,0 +1,17 @@
using DigitalData.Core.Abstractions.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.Core.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddDbRepository<TDbContext, TEntity>(this IServiceCollection services, Func<TDbContext, DbSet<TEntity>> queryFactory)
where TDbContext : DbContext
where TEntity : DbContext
{
return services
.AddScoped<IRepository<TEntity>, DbRepository<TDbContext, TEntity>>()
.AddSingleton(queryFactory);
}
}