Projektstruktur optimiert und Benutzer- & Gruppenverzeichnisdienste abgeschlossen.
This commit is contained in:
65
DigitalData.Core.Application/DIExtensions.cs
Normal file
65
DigitalData.Core.Application/DIExtensions.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Contracts.Application;
|
||||
using DigitalData.Core.Contracts.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.DirectoryServices;
|
||||
|
||||
namespace DigitalData.Core.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods to <see cref="IServiceCollection"/> for registering Clean Architecture CRUD related services and repositories.
|
||||
/// </summary>
|
||||
public static class DIExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a basic CRUD service for a specific DTO and entity type to the service collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto">The DTO type the service operates on.</typeparam>
|
||||
/// <typeparam name="TEntity">The entity type corresponding to the DTO.</typeparam>
|
||||
/// <typeparam name="TId">The type of the entity's identifier.</typeparam>
|
||||
/// <typeparam name="TProfile">The AutoMapper profile type for configuring mappings between the DTO and the entity.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <param name="configureService">An optional action to configure additional services for the CRUD service.</param>
|
||||
/// <returns>The original <see cref="IServiceCollection"/> instance, allowing further configuration.</returns>
|
||||
public static IServiceCollection AddCleanBasicCRUDService<TCRUDRepository, TDto, TEntity, TId, TProfile>(this IServiceCollection services, Action<IServiceCollection>? configureService = null)
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TDto : class where TEntity : class where TProfile : Profile
|
||||
{
|
||||
services.AddScoped<IBasicCRUDService<TCRUDRepository, TDto, TEntity, TId>, BasicCRUDService<TCRUDRepository, TDto, TEntity, TId>>();
|
||||
configureService?.Invoke(services);
|
||||
|
||||
services.AddAutoMapper(typeof(TProfile).Assembly);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a CRUD service for managing create, read, update, and delete operations for a specific set of DTOs and an entity type to the service collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCRUDRepository">The repository type that provides CRUD operations for entities of type TEntity.</typeparam>
|
||||
/// <typeparam name="TCreateDto">The DTO type used for create operations.</typeparam>
|
||||
/// <typeparam name="TReadDto">The DTO type used for read operations.</typeparam>
|
||||
/// <typeparam name="TUpdateDto">The DTO type used for update operations.</typeparam>
|
||||
/// <typeparam name="TEntity">The entity type corresponding to the DTOs.</typeparam>
|
||||
/// <typeparam name="TId">The type of the entity's identifier.</typeparam>
|
||||
/// <typeparam name="TProfile">The AutoMapper profile type for configuring mappings between the DTOs and the entity.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <param name="configureService">An optional action to configure additional services for the CRUD service.</param>
|
||||
/// <returns>The original <see cref="IServiceCollection"/> instance, allowing further configuration.</returns>
|
||||
public static IServiceCollection AddCleanCRUDService<TCRUDRepository, TCreateDto, TReadDto, TUpdateDto, TEntity, TId, TProfile>(this IServiceCollection services, Action<IServiceCollection>? configureService = null)
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TCreateDto : class where TReadDto : class where TUpdateDto : class where TEntity : class where TProfile : Profile
|
||||
{
|
||||
services.AddScoped<ICRUDService<TCRUDRepository, TCreateDto, TReadDto, TUpdateDto, TEntity, TId>, CRUDService<TCRUDRepository, TCreateDto, TReadDto, TUpdateDto, TEntity, TId>>();
|
||||
configureService?.Invoke(services);
|
||||
|
||||
services.AddAutoMapper(typeof(TProfile).Assembly);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddDirectoryService(this IServiceCollection service)
|
||||
{
|
||||
service.AddScoped<IDirectoryService, DirectoryService>();
|
||||
return service;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user