Erweiterung der DTOs und Implementierung der Lokalisierungsdienste

- Neue DTO-Extension-Methoden hinzugefügt, um die Verarbeitung und Zuweisung von Nachrichten und Benachrichtigungen in Ergebnisobjekten zu vereinfachen.
- Lokalisierungsunterstützung in der API-Schicht implementiert, einschließlich Cookie-basierter Lokalisierung und Konfiguration unterstützter Kulturen.
- Die Integration von StringLocalizer in die API-Schicht wurde durchgeführt, um eine nahtlose Mehrsprachigkeit zu ermöglichen.
- Fehlerbehandlung für fehlende Konfigurationseinstellungen verbessert.

Die Änderungen verbessern die Flexibilität und Wartbarkeit des Codes und unterstützen eine effizientere Internationalisierung der Anwendung.
This commit is contained in:
Developer 02
2024-04-30 17:01:26 +02:00
parent f6d8721c27
commit 4b71836fea
36 changed files with 303 additions and 1109 deletions

View File

@@ -1,58 +1,43 @@
using DigitalData.Core.Contracts.Infrastructure;
using DigitalData.Core.DTO;
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> : IServiceBase
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);
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 IServiceResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
Task<IServiceResult<TReadDto>> ReadByIdAsync(TId id);
/// <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 IServiceResult containing a collection of readDTOs representing all entities or an error message.</returns>
Task<IServiceResult<IEnumerable<TReadDto>>> ReadAllAsync();
/// <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 IServiceMessage indicating the outcome of the update operation, with an appropriate message.</returns>
Task<IServiceMessage> UpdateAsync(TUpdateDto updateDto);
/// <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 IServiceMessage indicating the outcome of the delete operation, with an appropriate message.</returns>
Task<IServiceMessage> DeleteAsyncById(TId id);
/// <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.

View File

@@ -1,8 +1,9 @@
using System.DirectoryServices;
using DigitalData.Core.DTO;
using System.DirectoryServices;
namespace DigitalData.Core.Contracts.Application
{
public interface IDirectorySearchService : IServiceBase
public interface IDirectorySearchService
{
public string ServerName { get; }
@@ -14,9 +15,9 @@ namespace DigitalData.Core.Contracts.Application
bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword);
IServiceResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
IServiceResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, 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);

View File

@@ -1,185 +0,0 @@
namespace DigitalData.Core.Contracts.Application
{
/// <summary>
/// Defines the base functionality for a service, including creating service messages and results.
/// </summary>
public interface IResponseService
{
#region WITHOUT_MESSAGE
/// <summary>
/// Creates a simple service message indicating success or failure without any additional messages.
/// </summary>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <returns>A service message indicating the outcome of the operation without any messages.</returns>
IServiceMessage CreateMessage(bool isSuccess);
/// <summary>
/// Creates a service result with the specified data and a success flag, without any additional messages.
/// </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>
/// <returns>A service result containing the data and indicating the outcome of the operation without any messages.</returns>
IServiceResult<T> CreateResult<T>(T? data, bool isSuccess);
/// <summary>
/// Creates a service message indicating a successful operation without any messages.
/// </summary>
/// <returns>A service message indicating a successful operation.</returns>
IServiceMessage Successful();
/// <summary>
/// Creates a service message indicating a failed operation without any messages.
/// </summary>
/// <returns>A service message indicating a failed operation.</returns>
IServiceMessage Failed();
/// <summary>
/// Creates a successful service result with the specified data, without any messages.
/// </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>
/// <returns>A successful service result containing the data, indicating a successful operation without any messages.</returns>
IServiceResult<T> Successful<T>(T data);
/// <summary>
/// Creates a failed service result, optionally including data, without any messages.
/// </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>
/// <returns>A failed service result, which may or may not contain data, indicating a failed operation without any messages.</returns>
IServiceResult<T> Failed<T>(T? data = default);
#endregion
#region WITH_STRING_MESSAGE
/// <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);
#endregion
#region WITH_ENUM_MESSAGE
/// <summary>
/// Creates a service message using enumeration values.
/// </summary>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <param name="messages">The enumeration values associated with the operation.</param>
/// <returns>A service message indicating the outcome of the operation and any associated enumeration values.</returns>
IServiceMessage CreateMessage(bool isSuccess, params Enum[] messages);
/// <summary>
/// Creates a service result with the specified data and enumeration values for messages.
/// </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 enumeration values associated with the operation.</param>
/// <returns>A service result containing the data and indicating the outcome of the operation with enumeration values.</returns>
IServiceResult<T> CreateResult<T>(T? data, bool isSuccess, params Enum[] messages);
/// <summary>
/// Creates a successful service message using enumeration values.
/// </summary>
/// <param name="messages">The success enumeration values.</param>
/// <returns>A successful service message.</returns>
IServiceMessage Successful(params Enum[] messages);
/// <summary>
/// Creates a failed service message using enumeration values.
/// </summary>
/// <param name="messages">The failure enumeration values.</param>
/// <returns>A failed service message.</returns>
IServiceMessage Failed(params Enum[] messages);
/// <summary>
/// Creates a successful service result with the specified data, using enumeration values for messages.
/// </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 enumeration values.</param>
/// <returns>A successful service result containing the data.</returns>
IServiceResult<T> Successful<T>(T data, params Enum[] messages);
/// <summary>
/// Creates a failed service result, optionally including data, using enumeration values for messages.
/// </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 enumeration values.</param>
/// <returns>A failed service result, which may or may not contain data.</returns>
IServiceResult<T> Failed<T>(T? data = default, params Enum[] messages);
/// <summary>
/// Creates a failed service result without explicitly including data, using only enumeration values for 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 enumeration values.
/// </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 enumeration values 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 Enum[] messages);
#endregion
}
}

View File

@@ -1,6 +0,0 @@
namespace DigitalData.Core.Contracts.Application
{
public interface IServiceBase : IResponseService
{
}
}

View File

@@ -1,95 +0,0 @@
using System.Text.Json.Serialization;
namespace DigitalData.Core.Contracts.Application
{
/// <summary>
/// Defines a structured format for service messages, categorizing them into success indicators and various types of messages.
/// This interface segregates messages into client-facing messages and different levels of logging messages, facilitating targeted communications and diagnostics.
/// Properties are initialized once per instance and cannot be modified afterwards, promoting immutability.
/// </summary>
public interface IServiceMessage
{
/// <summary>
/// Gets or sets a value indicating whether the service operation was successful.
/// </summary>
bool IsSuccess { get; set; }
/// <summary>
/// Represents the list of flags that indicate specific types of statuses or conditions in a service operation.
/// These flags help in categorizing the state of the operation more granularly, allowing for multiple conditions to be represented simultaneously.
/// </summary>
[JsonIgnore]
public ICollection<Enum> Flags { get; }
/// <summary>
/// Checks if any of the current service message's flags matches the specified flag based on their string representations.
/// This method is useful for conditional logic where the exact string representation of the flag values is crucial.
/// </summary>
/// <param name="flag">The flag to check against the current service message's flags.</param>
/// <returns>true if a flag with a matching string representation exists; otherwise, false.</returns>
public bool HasFlag(Enum flag) => Flags.Any(f => f.ToString() == flag.ToString());
/// <summary>
/// [Obsolete("Deprecated: Use ClientMessages instead.")]
/// Gets 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>
[Obsolete("Deprecated: Use ClientMessages instead.")]
ICollection<string> Messages { get; init; }
/// <summary>
/// Gets a collection of messages intended for client display. This replaces the deprecated 'Messages' property.
/// </summary>
ICollection<string> ClientMessages { get; init; }
/// <summary>
/// Gets a collection of messages used for tracing program execution at a fine-grained level. These are typically voluminous and detailed.
/// </summary>
[JsonIgnore]
ICollection<string> TraceMessages { get; init; }
/// <summary>
/// Gets a collection of messages helpful for debugging during development. These messages are often diagnostic.
/// </summary>
[JsonIgnore]
ICollection<string> DebugMessages { get; init; }
/// <summary>
/// Gets a collection of informational messages, less critical than warnings, generally used for non-critical notifications.
/// </summary>
[JsonIgnore]
ICollection<string> InformationMessages { get; init; }
/// <summary>
/// Gets a collection of messages indicating potential issues that are not necessarily errors, but which may require attention.
/// </summary>
[JsonIgnore]
ICollection<string> WarningMessages { get; init; }
/// <summary>
/// Gets a collection of error messages indicating failures or problems within the service.
/// </summary>
[JsonIgnore]
ICollection<string> ErrorMessages { get; init; }
/// <summary>
/// Gets a collection of messages indicating critical issues that require immediate attention.
/// </summary>
[JsonIgnore]
ICollection<string> CriticalMessages { get; init; }
/// <summary>
/// Adds a new message to the appropriate collection based on the message type.
/// </summary>
/// <param name="message">The message to add.</param>
/// <returns>The current instance of IServiceMessage, allowing for method chaining.</returns>
IServiceMessage WithMessage(string message);
/// <summary>
/// Adds a message corresponding to a specified message key to the appropriate collection, facilitating localization and standardization.
/// </summary>
/// <param name="messageKey">The enum value representing the message key.</param>
/// <returns>The current instance of IServiceMessage, allowing for method chaining.</returns>
IServiceMessage WithMessageKey(Enum messageKey);
}
}

View File

@@ -1,19 +0,0 @@
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; }
}
}

View File

@@ -24,6 +24,10 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.Core.DTO\DigitalData.Core.DTO.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="icon.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>

View File

@@ -0,0 +1,7 @@
namespace DigitalData.Core.Contracts
{
internal interface IError
{
}
}