Refaktorieren: Projektname von "Contracts" zu "Abstractions" geändert, um den Zweck besser widerzuspiegeln.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using DigitalData.Core.Abstractions.Infrastructure;
|
||||
|
||||
namespace DigitalData.Core.Abstractions.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements a simplified CRUD service interface that uses a single Data Transfer Object (DTO) type for all CRUD operations,
|
||||
/// streamlining the process for entities where the same DTO can be used for creating, reading, updating, and deleting entities.
|
||||
/// This interface inherits from the ICRUDService interface, applying the same DTO type for all generic type parameters,
|
||||
/// thereby simplifying the usage for cases where a single DTO is sufficient for all operations on an entity.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto">The type of the Data Transfer Object used for all CRUD operations.</typeparam>
|
||||
/// <typeparam name="TEntity">The type of the entity this service maps to.</typeparam>
|
||||
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
|
||||
/// <remarks>
|
||||
/// This interface is useful for entities that do not require different DTOs for different operations,
|
||||
/// allowing for a more concise and maintainable codebase when implementing services for such entities.
|
||||
/// </remarks>
|
||||
public interface IBasicCRUDService<TDto, TEntity, TId> : ICRUDService<TDto, TDto, TDto, TEntity, TId>
|
||||
where TDto : class where TEntity : class
|
||||
{
|
||||
}
|
||||
}
|
||||
60
DigitalData.Core.Abstractions/Application/ICRUDService.cs
Normal file
60
DigitalData.Core.Abstractions/Application/ICRUDService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using DigitalData.Core.Abstractions.Infrastructure;
|
||||
using DigitalData.Core.DTO;
|
||||
|
||||
namespace DigitalData.Core.Abstractions.Application
|
||||
{
|
||||
public interface ICRUDService<TCreateDto, TReadDto, TUpdateDto, TEntity, TId>
|
||||
where TCreateDto : class where TReadDto : class where TUpdateDto : class where TEntity : class
|
||||
{
|
||||
Task<DataResult<TId>> CreateAsync(TCreateDto createDto);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult,
|
||||
/// including the readDTO on success or null and an error message on failure.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the entity to retrieve.</param>
|
||||
/// <returns>An DataResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
|
||||
Task<DataResult<TReadDto>> ReadByIdAsync(TId id);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult,
|
||||
/// including a collection of readDTOs on success or an error message on failure.
|
||||
/// </summary>
|
||||
/// <returns>An DataResult containing a collection of readDTOs representing all entities or an error message.</returns>
|
||||
Task<DataResult<IEnumerable<TReadDto>>> ReadAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
|
||||
/// indicating the success or failure of the operation, including the error messages on failure.
|
||||
/// </summary>
|
||||
/// <param name="updateDto">The updateDTO with updated values for the entity.</param>
|
||||
/// <returns>An Result indicating the outcome of the update operation, with an appropriate message.</returns>
|
||||
Task<Result> UpdateAsync(TUpdateDto updateDto);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage,
|
||||
/// indicating the success or failure of the operation, including the error messages on failure.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the entity to delete.</param>
|
||||
/// <returns>An Result indicating the outcome of the delete operation, with an appropriate message.</returns>
|
||||
Task<Result> DeleteAsyncById(TId id);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the entity to check.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.</returns>
|
||||
Task<bool> HasEntity(TId id);
|
||||
|
||||
/// <summary>
|
||||
/// Handles exceptions that occur within service actions. This method should log the exception
|
||||
/// and return an String that contains information about the error, which can then be sent to the client.
|
||||
/// The implementation should determine the appropriate level of detail to include in the error message
|
||||
/// based on security and usability considerations.
|
||||
/// </summary>
|
||||
/// <param name="ex">The exception that occurred during the controller action.</param>
|
||||
/// <returns>An string instance representing the outcome of the error handling process.
|
||||
/// This includes a flag indicating the operation was unsuccessful and any relevant error messages.</returns>
|
||||
string HandleException(Exception ex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using DigitalData.Core.DTO;
|
||||
using System.DirectoryServices;
|
||||
|
||||
namespace DigitalData.Core.Abstractions.Application
|
||||
{
|
||||
public interface IDirectorySearchService
|
||||
{
|
||||
public string ServerName { get; }
|
||||
|
||||
public string Root { get; }
|
||||
|
||||
string SearchRootPath { get; }
|
||||
|
||||
Dictionary<string, string> CustomSearchFilters { get; }
|
||||
|
||||
bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword);
|
||||
|
||||
DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||
|
||||
DataResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||
|
||||
void SetSearchRootCache(string username, string password);
|
||||
|
||||
DirectoryEntry? GetSearchRootCache(string username);
|
||||
}
|
||||
}
|
||||
41
DigitalData.Core.Abstractions/Application/IJWTService.cs
Normal file
41
DigitalData.Core.Abstractions/Application/IJWTService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace DigitalData.Core.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the operations for JWT service handling claims of type <typeparamref name="TClaimValue"/>.
|
||||
/// </summary>
|
||||
public interface IJWTService<TClaimValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a symmetric security key with the specified byte size.
|
||||
/// </summary>
|
||||
/// <param name="byteSize">The size of the security key in bytes. Default is 32 bytes.</param>
|
||||
/// <returns>A new instance of <see cref="SymmetricSecurityKey"/>.</returns>
|
||||
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
|
||||
{
|
||||
using var rng = RandomNumberGenerator.Create();
|
||||
var randomBytes = new byte[byteSize];
|
||||
rng.GetBytes(randomBytes);
|
||||
var securityKey = new SymmetricSecurityKey(randomBytes);
|
||||
|
||||
return securityKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a token based on the specified claim value.
|
||||
/// </summary>
|
||||
/// <param name="claimValue">The claim value to encode in the token.</param>
|
||||
/// <returns>A JWT as a string.</returns>
|
||||
string GenerateToken(TClaimValue claimValue);
|
||||
|
||||
/// <summary>
|
||||
/// Reads and validates a security token from a string representation.
|
||||
/// </summary>
|
||||
/// <param name="token">The JWT to read.</param>
|
||||
/// <returns>A <see cref="JwtSecurityToken"/> if the token is valid; otherwise, null.</returns>
|
||||
JwtSecurityToken? ReadSecurityToken(string token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user