Developer 02 3a1aeb7ac3 Refactor namespaces and enhance application structure
This commit reorganizes namespaces from `DigitalData.Core.Abstractions` and `DigitalData.Core.DTO` to `DigitalData.Core.Application.Interfaces` and `DigitalData.Core.Application.DTO`, improving maintainability and clarity.

Updated using directives across multiple files to reflect the new structure, ensuring functionality remains intact.

Project references in `DigitalData.Core.API.csproj` have been consolidated to include the new Application project.

Introduced new classes and interfaces such as `BaseDTO`, `CookieConsentSettings`, `DataResult`, `Notice`, and `Result` to enhance data transfer and service result handling.

Updated `IRepository`, `ICRUDRepository`, and `IEntityMapper` interfaces to facilitate CRUD operations and entity mapping.

Added extension methods in `Extensions.cs` to improve repository usability.

New interfaces for HTTP client services have been added, enhancing external API call handling.

Overall, these changes reflect a significant restructuring aimed at improving organization and preparing for future development.
2025-05-16 11:24:58 +02:00

50 lines
3.0 KiB
C#

using DigitalData.Core.Application.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
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 the directory search service to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="service">The <see cref="IServiceCollection"/> to add services to.</param>
/// <param name="directorySearchOptions">
/// Optional. An instance of <see cref="DirectorySearchOptions"/> to configure the directory search service.
/// If not provided, the options need to be configured separately.
/// </param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
/// <remarks>
/// This method adds the necessary services for directory search functionality, including memory caching.
/// If <paramref name="directorySearchOptions"/> is not provided, ensure to configure the options separately
/// using the <see cref="IOptions{TOptions}"/> pattern.
/// </remarks>
public static IServiceCollection AddDirectorySearchService(this IServiceCollection service, IConfigurationSection directorySearchOptions)
{
return service.Configure<DirectorySearchOptions>(directorySearchOptions)
.AddMemoryCache()
.AddScoped<IDirectorySearchService, DirectorySearchService>();
}
/// <summary>
/// Adds the JWT service to the <see cref="IServiceCollection"/>.
/// </summary>
/// <typeparam name="TClaimValue">The type of the claim value used in the JWT token.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <param name="tokenDescriptorFactory">A function that takes a claim value of type <typeparamref name="TClaimValue"/> and returns a <see cref="SecurityTokenDescriptor"/> used to configure the JWT token.</param>
/// <returns>The original <see cref="IServiceCollection"/> instance, allowing further configuration.</returns>
/// <remarks>
/// This method adds the necessary services for handling JWT tokens. The <paramref name="tokenDescriptorFactory"/> function is used to generate the <see cref="SecurityTokenDescriptor"/> which is essential for creating the JWT tokens.
/// </remarks>
public static IServiceCollection AddJWTService<TClaimValue>(this IServiceCollection services, Func<TClaimValue, SecurityTokenDescriptor> tokenDescriptorFactory)
{
return services.AddScoped<IJWTService<TClaimValue>, JWTService<TClaimValue>>(provider => new (tokenDescriptorFactory));
}
}
}