feat(EntityConfigurationOptions): Erstellt, um Entitäten wie Mapper konfigurieren zu können
This commit is contained in:
@@ -6,12 +6,14 @@ namespace DigitalData.Core.Infrastructure;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddDbRepository<TDbContext, TEntity>(this IServiceCollection services, Func<TDbContext, DbSet<TEntity>> queryFactory)
|
||||
public static EntityConfigurationOptions<TEntity> AddDbRepository<TDbContext, TEntity>(this IServiceCollection services, Func<TDbContext, DbSet<TEntity>> queryFactory)
|
||||
where TDbContext : DbContext
|
||||
where TEntity : class
|
||||
{
|
||||
return services
|
||||
services
|
||||
.AddScoped<IRepository<TEntity>, DbRepository<TDbContext, TEntity>>()
|
||||
.AddSingleton(queryFactory);
|
||||
|
||||
return new EntityConfigurationOptions<TEntity>(services);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using DigitalData.Core.Abstractions.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure;
|
||||
|
||||
public class EntityConfigurationOptions<TEntity>
|
||||
{
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
public EntityConfigurationOptions(IServiceCollection services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public EntityConfigurationOptions<TEntity> AddCustomMapper(Func<IServiceProvider, IEntityMapper<TEntity>> factory)
|
||||
{
|
||||
_services.AddSingleton(factory);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user