Developer 02 0bf8979a09 refactor: Einführung des IUnique<TId>-Interfaces für Entitäten und DTOs
- Aktualisiertes IBasicCRUDService-Interface, um Konsistenz bei einzigartigen Identifikatoren mit IUnique<TId> durchzusetzen
- DIExtensions-Methoden angepasst, um IUnique<TId>-Einschränkungen für DTOs und Entitäten einzuschließen
2024-09-13 16:30:52 +02:00

28 lines
1.6 KiB
C#

using DigitalData.Core.Abstractions;
using DigitalData.Core.Abstractions.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.DirectoryServices;
namespace DigitalData.Core.Infrastructure
{
public static class DIExtensions
{
/// <summary>
/// Adds a CRUD repository for a specific entity type to the service collection.
/// </summary>
/// <typeparam name="TEntity">The entity type for which the repository is registered.</typeparam>
/// <typeparam name="TId">The type of the entity's identifier.</typeparam>
/// <typeparam name="TDbContext">The DbContext type used by the repository.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/> to add the repository to.</param>
/// <param name="configureRepository">An optional action to configure additional services for the repository.</param>
/// <returns>The original <see cref="IServiceCollection"/> instance, allowing further configuration.</returns>
public static IServiceCollection AddCleanCRUDRepository<TEntity, TId, TDbContext, TCRUDRepository>(this IServiceCollection services, Action<IServiceCollection>? configureRepository = null)
where TCRUDRepository : CRUDRepository<TEntity, TId, TDbContext> where TEntity : class, IUnique<TId> where TDbContext : DbContext
{
services.AddScoped<ICRUDRepository<TEntity, TId>, TCRUDRepository>();
configureRepository?.Invoke(services);
return services;
}
}
}