Modified `AddDbRepository` method to allow broader entity types and registered `queryFactory` as a singleton. Added necessary using directives in `DbRepositoryTests.cs` and updated the `Setup` method to configure an in-memory database for testing with `MockDbContext` and `User` entity.
17 lines
609 B
C#
17 lines
609 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 : class
|
|
{
|
|
return services
|
|
.AddScoped<IRepository<TEntity>, DbRepository<TDbContext, TEntity>>()
|
|
.AddSingleton(queryFactory);
|
|
}
|
|
} |