Projektstruktur optimiert und Benutzer- & Gruppenverzeichnisdienste abgeschlossen.
This commit is contained in:
23
DigitalData.Core.Contracts/Application/IBasicCRUDService.cs
Normal file
23
DigitalData.Core.Contracts/Application/IBasicCRUDService.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using DigitalData.Core.Contracts.Infrastructure;
|
||||
|
||||
namespace DigitalData.Core.Contracts.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="TCRUDRepository">The repository type that provides CRUD operations for entities of type TEntity.</typeparam>
|
||||
/// <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<TCRUDRepository, TDto, TEntity, TId> : ICRUDService<TCRUDRepository, TDto, TDto, TDto, TEntity, TId>
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TDto : class where TEntity : class
|
||||
{
|
||||
}
|
||||
}
|
||||
75
DigitalData.Core.Contracts/Application/ICRUDService.cs
Normal file
75
DigitalData.Core.Contracts/Application/ICRUDService.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using DigitalData.Core.Contracts.Infrastructure;
|
||||
|
||||
namespace DigitalData.Core.Contracts.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the contract for CRUD operations at the service level using Data Transfer Objects (DTOs) for entities of type TEntity,
|
||||
/// wrapped in an IServiceResult to encapsulate the outcome of the operation, including success, data, and error messages.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCRUDRepository">The repository type that provides CRUD operations for entities of type TEntity.</typeparam>
|
||||
/// <typeparam name="TCreateDto">The type of the Data Transfer Object this service works with to create new entity.</typeparam>
|
||||
/// <typeparam name="TReadDto">The type of the Data Transfer Object this service works with to read new entity.</typeparam>
|
||||
/// <typeparam name="TUpdateDto">The type of the Data Transfer Object this service works with to update new entity.</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>
|
||||
public interface ICRUDService<TCRUDRepository, TCreateDto, TReadDto, TUpdateDto, TEntity, TId>
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TCreateDto : class where TReadDto : class where TUpdateDto : class where TEntity : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new entity based on the provided DTO and returns the result wrapped in an IServiceResult,
|
||||
/// including the created entity on success or an error message on failure.
|
||||
/// </summary>
|
||||
/// <param name="createDto">The createDto to create a new entity from.</param>
|
||||
/// <returns>An IServiceResult containing the id of created entity or an error message.</returns>
|
||||
Task<IServiceResult<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 IServiceResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
|
||||
Task<IServiceResult<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 IServiceResult containing a collection of readDTOs representing all entities or an error message.</returns>
|
||||
Task<IServiceResult<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 IServiceMessage indicating the outcome of the update operation, with an appropriate message.</returns>
|
||||
Task<IServiceMessage> 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 IServiceMessage indicating the outcome of the delete operation, with an appropriate message.</returns>
|
||||
Task<IServiceMessage> 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);
|
||||
}
|
||||
}
|
||||
15
DigitalData.Core.Contracts/Application/IDirectoryService.cs
Normal file
15
DigitalData.Core.Contracts/Application/IDirectoryService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.DirectoryServices;
|
||||
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
|
||||
namespace DigitalData.Core.Contracts.Application
|
||||
{
|
||||
public interface IDirectoryService : IServiceBase
|
||||
{
|
||||
IServiceResult<IEnumerable<ResultPropertyCollection>> ReadAllGroupAsCollection();
|
||||
|
||||
IServiceResult<IEnumerable<Dictionary<string, object>>> ReadGroupByPropertyName(string propName);
|
||||
|
||||
IServiceResult<IEnumerable<UserPrincipalDto>> ReadUserByGroup<UserPrincipalDto>(string groupIdentityValue, IdentityType groupIdentityType = IdentityType.Name, bool recursive = true);
|
||||
}
|
||||
}
|
||||
71
DigitalData.Core.Contracts/Application/IServiceBase.cs
Normal file
71
DigitalData.Core.Contracts/Application/IServiceBase.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
namespace DigitalData.Core.Contracts.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the base functionality for a service, including creating service messages and results.
|
||||
/// </summary>
|
||||
public interface IServiceBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a service message.
|
||||
/// </summary>
|
||||
/// <param name="isSuccess">Indicates if the operation was successful.</param>
|
||||
/// <param name="messages">The messages associated with the operation.</param>
|
||||
/// <returns>A service message indicating the outcome of the operation and any associated messages.</returns>
|
||||
IServiceMessage CreateMessage(bool isSuccess, params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a service result with the specified data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of data the service result will contain.</typeparam>
|
||||
/// <param name="data">The data for the service result.</param>
|
||||
/// <param name="isSuccess">Indicates if the operation was successful.</param>
|
||||
/// <param name="messages">The messages associated with the operation.</param>
|
||||
/// <returns>A service result containing the data and indicating the outcome of the operation.</returns>
|
||||
IServiceResult<T> CreateResult<T>(T? data, bool isSuccess, params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a successful service message.
|
||||
/// </summary>
|
||||
/// <param name="messages">The success messages.</param>
|
||||
/// <returns>A successful service message.</returns>
|
||||
IServiceMessage Successful(params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a failed service message.
|
||||
/// </summary>
|
||||
/// <param name="messages">The failure messages.</param>
|
||||
/// <returns>A failed service message.</returns>
|
||||
IServiceMessage Failed(params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a successful service result with the specified data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of data the service result will contain.</typeparam>
|
||||
/// <param name="data">The data to include in the service result.</param>
|
||||
/// <param name="messages">The success messages.</param>
|
||||
/// <returns>A successful service result containing the data.</returns>
|
||||
IServiceResult<T> Successful<T>(T data, params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a failed service result, optionally including data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of data the service result can contain.</typeparam>
|
||||
/// <param name="data">Optional data to include in the failed service result.</param>
|
||||
/// <param name="messages">The failure messages.</param>
|
||||
/// <returns>A failed service result, which may or may not contain data.</returns>
|
||||
IServiceResult<T> Failed<T>(T? data = default, params string[] messages);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a failed service result without explicitly including data, using only failure messages.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This overload is useful when you want to indicate a failure without the need to return any specific data,
|
||||
/// but still want to provide details about the failure through messages.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The type of data the service result can contain. The result will contain the default value for this type.</typeparam>
|
||||
/// <param name="messages">An array of failure messages associated with the operation. These provide detail about why the operation failed.</param>
|
||||
/// <returns>A failed service result. The data part of the result will be set to the default value for the specified type.</returns>
|
||||
IServiceResult<T> Failed<T>(params string[] messages);
|
||||
|
||||
}
|
||||
}
|
||||
21
DigitalData.Core.Contracts/Application/IServiceMessage.cs
Normal file
21
DigitalData.Core.Contracts/Application/IServiceMessage.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace DigitalData.Core.Contracts.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a basic structure for service messages, including a success flag and a collection of messages.
|
||||
/// This interface is intended to be a base for more specific service result types, offering a way to communicate
|
||||
/// operation outcomes (success or failure) along with relevant messages.
|
||||
/// </summary>
|
||||
public interface IServiceMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the service operation was successful.
|
||||
/// </summary>
|
||||
bool IsSuccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a collection of messages associated with the service operation. These messages can be error descriptions,
|
||||
/// success notifications, or other relevant information related to the operation's outcome.
|
||||
/// </summary>
|
||||
List<string> Messages { get; set; }
|
||||
}
|
||||
}
|
||||
19
DigitalData.Core.Contracts/Application/IServiceResult.cs
Normal file
19
DigitalData.Core.Contracts/Application/IServiceResult.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace DigitalData.Core.Contracts.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the outcome of a service operation, extending IServiceMessage with the addition of a data payload.
|
||||
/// This interface is generic, allowing for the specification of the type of data returned by the service operation.
|
||||
/// It is used to communicate not just the success or failure of an operation, but also to return any relevant data
|
||||
/// along with the operation's outcome.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data associated with the service operation's outcome. This could be a model,
|
||||
/// a collection of models, or any other type relevant to the operation.</typeparam>
|
||||
public interface IServiceResult<T> : IServiceMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the data resulting from the service operation. This property is nullable to accommodate operations
|
||||
/// that might not return data upon failure.
|
||||
/// </summary>
|
||||
T? Data { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user