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.
17 lines
613 B
C#
17 lines
613 B
C#
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);
|
|
}
|
|
} |