Funktion: Erweiterung von IServiceMessage mit Methoden zur Nachrichtenverwaltung

- Hinzufügen von Erweiterungsmethoden zu IServiceMessage für das Hinzufügen von Client-, Trace-, Debug-, Informations-, Warn-, Fehler- und kritischen Nachrichten.
- Einbeziehung von Methoden für direkte Nachrichten und auf Enum basierende Schlüssel, die Lokalisierung und benutzerdefinierte Formatierung unterstützen.
This commit is contained in:
Developer 02 2024-04-19 14:08:33 +02:00
parent ce462a8b66
commit 36889df1c0
41 changed files with 372 additions and 60 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
using AutoMapper;
namespace DigitalData.Core.Application
{
public static class AutoMapperExtension
{
/// <summary>
/// Maps a source object to a destination object, or throws an exception if the mapping result is null.
/// </summary>
/// <typeparam name="TSource">The source object type.</typeparam>
/// <typeparam name="TDestination">The destination object type.</typeparam>
/// <param name="source">The source object to map from.</param>
/// <returns>The mapped destination object.</returns>
/// <exception cref="MappingResultNullException">Thrown when the mapping result is null.</exception>
public static TDestination MapOrThrow<TDestination>(this IMapper mapper, object source)
{
return mapper.Map<TDestination>(source) ?? throw new AutoMapperMappingException(
$"Mapping to {typeof(TDestination).FullName} resulted in a null object. " +
"Hint: Ensure that the AutoMapper profile configuration for this mapping is correct.");
}
}
}

View File

@ -20,7 +20,6 @@ namespace DigitalData.Core.Application
{
protected readonly TCRUDRepository _repository;
protected readonly IMapper _mapper;
protected readonly IKeyTranslationService _translationService;
protected readonly PropertyInfo? _keyPropertyInfo;
/// <summary>
@ -29,10 +28,9 @@ namespace DigitalData.Core.Application
/// <param name="repository">The CRUD repository for accessing the database.</param>
/// <param name="translationService">The service for translating messages based on culture.</param>
/// <param name="mapper">The AutoMapper instance for mapping between DTOs and entity objects.</param>
public CRUDService(TCRUDRepository repository, IKeyTranslationService translationService, IMapper mapper)
public CRUDService(TCRUDRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(translationService)
{
_repository = repository;
_translationService = translationService;
_mapper = mapper;
_keyPropertyInfo = typeof(TEntity).GetProperties()
@ -96,7 +94,7 @@ namespace DigitalData.Core.Application
else
{
var translatedMessage = _translationService.Translate(MessageKey.UpdateFailed);
return Failed(translatedMessage);
return Failed();
}
}

View File

@ -5,6 +5,7 @@ using System.DirectoryServices;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using System.DirectoryServices.AccountManagement;
using DigitalData.Core.Contracts.CultureServices;
namespace DigitalData.Core.Application
{
@ -18,7 +19,7 @@ namespace DigitalData.Core.Application
private readonly DateTimeOffset _userCacheExpiration;
public Dictionary<string, string> CustomSearchFilters { get; }
public DirectorySearchService(IConfiguration configuration, ILogger<DirectorySearchService> logger, IMemoryCache memoryCache)
public DirectorySearchService(IConfiguration configuration, ILogger<DirectorySearchService> logger, IMemoryCache memoryCache, IKeyTranslationService translationService) : base(translationService)
{
_memoryCache = memoryCache;

View File

@ -1,13 +1,17 @@
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace DigitalData.Core.Application
{
/// <summary>
/// Provides a base implementation of <see cref="IServiceBase"/>, offering basic service messaging and result creation functionalities.
/// </summary>
public class ResponseService : IResponseService
{
protected readonly IKeyTranslationService _translationService;
public ResponseService(IKeyTranslationService translationService)
{
_translationService = translationService;
}
#region WITHOUT_MESSAGE
@ -16,7 +20,11 @@ namespace DigitalData.Core.Application
/// </summary>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <returns>A service message reflecting the operation outcome.</returns>
public IServiceMessage CreateMessage(bool isSuccess) => new ServiceMessage(isSuccess);
public IServiceMessage CreateMessage(bool isSuccess = false) => new ServiceMessage()
{
IsSuccess = isSuccess,
KeyTranslator = _translationService.Translate
};
/// <summary>
/// Creates a service result containing the provided data and a success flag, without additional messages.
@ -25,7 +33,12 @@ namespace DigitalData.Core.Application
/// <param name="data">The data to include in the result.</param>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <returns>A service result with the specified data and outcome.</returns>
public IServiceResult<T> CreateResult<T>(T? data, bool isSuccess) => new ServiceResult<T>(data, isSuccess);
public IServiceResult<T> CreateResult<T>(T? data = default, bool isSuccess = false) => new ServiceResult<T>()
{
IsSuccess = isSuccess,
Data = data,
KeyTranslator = _translationService.Translate
};
/// <summary>
/// Creates a service message indicating a successful operation without additional messages.
@ -56,9 +69,8 @@ namespace DigitalData.Core.Application
public IServiceResult<T> Failed<T>(T? data = default) => CreateResult(data, false);
#endregion
#region WITH_STRING_MESSAGE
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a service message with the specified success flag and messages.
/// </summary>
@ -67,6 +79,7 @@ namespace DigitalData.Core.Application
/// <returns>A new instance of <see cref="ServiceMessage"/> reflecting the operation outcome.</returns>
public virtual IServiceMessage CreateMessage(bool isSuccess, params string[] messages) => new ServiceMessage(isSuccess, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a service result containing the provided data, success flag, and messages.
/// </summary>
@ -77,6 +90,7 @@ namespace DigitalData.Core.Application
/// <returns>A new instance of <see cref="ServiceResult{T}"/> with the specified data and outcome.</returns>
public virtual IServiceResult<T> CreateResult<T>(T? data = default, bool isSuccess = true, params string[] messages) => new ServiceResult<T>(data, isSuccess, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a successful service message.
/// </summary>
@ -84,6 +98,7 @@ namespace DigitalData.Core.Application
/// <returns>A successful service message.</returns>
public virtual IServiceMessage Successful(params string[] messages) => CreateMessage(true, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service message.
/// </summary>
@ -91,6 +106,7 @@ namespace DigitalData.Core.Application
/// <returns>A failed service message.</returns>
public virtual IServiceMessage Failed(params string[] messages) => CreateMessage(false, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a successful service result with the provided data.
/// </summary>
@ -100,6 +116,7 @@ namespace DigitalData.Core.Application
/// <returns>A successful service result containing the specified data.</returns>
public virtual IServiceResult<T> Successful<T>(T data, params string[] messages) => CreateResult(data, true, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service result, optionally including data.
/// </summary>
@ -109,6 +126,7 @@ namespace DigitalData.Core.Application
/// <returns>A failed service result, which may or may not contain the specified data.</returns>
public virtual IServiceResult<T> Failed<T>(T? data = default, params string[] messages) => CreateResult(data, false, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service result using only failure messages, without explicitly including data.
/// </summary>
@ -125,6 +143,7 @@ namespace DigitalData.Core.Application
#endregion
#region WITH_ENUM_MESSAGE
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a service message with the specified success flag and enumeration messages.
/// </summary>
@ -133,6 +152,7 @@ namespace DigitalData.Core.Application
/// <returns>A new instance of <see cref="ServiceMessage"/> reflecting the operation outcome with enumeration messages.</returns>
public IServiceMessage CreateMessage(bool isSuccess, params Enum[] messages) => CreateMessage(isSuccess, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a service result containing the provided data, success flag, and enumeration messages.
/// </summary>
@ -143,6 +163,7 @@ namespace DigitalData.Core.Application
/// <returns>A new instance of <see cref="ServiceResult{T}"/> with the specified data and outcome using enumeration messages.</returns>
public IServiceResult<T> CreateResult<T>(T? data, bool isSuccess, params Enum[] messages) => CreateResult(data, isSuccess, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a successful service message using enumeration messages.
/// </summary>
@ -150,6 +171,7 @@ namespace DigitalData.Core.Application
/// <returns>A successful service message.</returns>
public IServiceMessage Successful(params Enum[] messages) => CreateMessage(true, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service message using enumeration messages.
/// </summary>
@ -157,6 +179,7 @@ namespace DigitalData.Core.Application
/// <returns>A failed service message.</returns>
public IServiceMessage Failed(params Enum[] messages) => CreateMessage(false, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a successful service result with the provided data using enumeration messages.
/// </summary>
@ -166,6 +189,7 @@ namespace DigitalData.Core.Application
/// <returns>A successful service result containing the specified data.</returns>
public IServiceResult<T> Successful<T>(T data, params Enum[] messages) => CreateResult(data, true, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service result, optionally including data, using enumeration messages.
/// </summary>
@ -175,6 +199,7 @@ namespace DigitalData.Core.Application
/// <returns>A failed service result, which may or may not contain the specified data.</returns>
public IServiceResult<T> Failed<T>(T? data = default, params Enum[] messages) => CreateResult(data, false, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
/// <summary>
/// Creates a failed service result using only failure messages, without explicitly including data.
/// </summary>

View File

@ -1,31 +1,16 @@
using AutoMapper;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
namespace DigitalData.Core.Application
{
/// <summary>
/// Provides a base implementation of <see cref="IServiceBase"/>, offering basic service messaging and result creation functionalities.
/// Provides a base implementation of <see cref="IServiceBase"/>.
/// </summary>
public class ServiceBase : ResponseService, IServiceBase, IResponseService
{
}
public static class AutoMapperExtension
{
/// <summary>
/// Maps a source object to a destination object, or throws an exception if the mapping result is null.
/// </summary>
/// <typeparam name="TSource">The source object type.</typeparam>
/// <typeparam name="TDestination">The destination object type.</typeparam>
/// <param name="source">The source object to map from.</param>
/// <returns>The mapped destination object.</returns>
/// <exception cref="MappingResultNullException">Thrown when the mapping result is null.</exception>
public static TDestination MapOrThrow<TDestination>(this IMapper mapper, object source)
public ServiceBase(IKeyTranslationService translationService) : base(translationService)
{
return mapper.Map<TDestination>(source) ?? throw new AutoMapperMappingException(
$"Mapping to {typeof(TDestination).FullName} resulted in a null object. " +
"Hint: Ensure that the AutoMapper profile configuration for this mapping is correct.");
}
}
}

View File

@ -1,40 +1,113 @@
using DigitalData.Core.Contracts.Application;
using System.Text.Json.Serialization;
namespace DigitalData.Core.Application
{
/// <summary>
/// Represents the outcome of a service operation, encapsulating the success or failure status,
/// and any associated messages.
/// Represents the outcome of a service operation, encapsulating the success or failure status,
/// and any associated messages. It also supports optional translation of message keys for localization purposes.
/// </summary>
public class ServiceMessage : IServiceMessage
{
/// <summary>
/// Initializes a new instance of the ServiceMessage class.
/// </summary>
public ServiceMessage()
{
}
/// <summary>
/// Initializes a new instance of the ServiceMessage class, specifying the success status.
/// Optionally, a function for translating message keys can be provided.
/// If a translation function is provided, it will be used for both string and enum message keys.
/// </summary>
/// <param name="isSuccess">Indicates whether the service operation was successful.</param>
/// If provided, it will also be adapted for translating enum keys by converting them to strings first.</param>
[Obsolete("Deprecated: initialize objects using object initializer.")]
public ServiceMessage(bool isSuccess)
{
IsSuccess = isSuccess;
}
/// <summary>
/// Initializes a new instance of the ServiceMessage class with specified success status, and messages.
/// </summary>
/// <param name="isSuccess">Indicates whether the service operation was successful.</param>
/// <param name="data">The data associated with a successful operation.</param>
/// <param name="messages">An array of messages related to the operation's outcome.</param>
[Obsolete("Deprecated: initialize objects using object initializer.")]
public ServiceMessage(bool isSuccess, params string[] messages)
{
IsSuccess = isSuccess;
Messages = messages.ToList<string>();
}
/// <summary>
/// Gets or sets a value indicating whether the service operation was successful.
/// </summary>
public bool IsSuccess { get; set; }
public bool IsSuccess { get; set; } = false;
/// <summary>
/// Gets or sets a collection of messages associated with the service operation.
/// [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>
public List<string> Messages { get; set; } = new List<string>();
[Obsolete("Deprecated: Use ClientMessages instead.")]
public List<string> Messages { get; init; } = new();
/// <summary>
/// Gets a collection of messages intended for client display. This replaces the deprecated 'Messages' property.
/// </summary>
public List<string> ClientMessages { get; init; } = new();
/// <summary>
/// Gets a collection of messages used for tracing program execution at a fine-grained level. These are typically voluminous and detailed.
/// </summary>
[JsonIgnore]
public List<string> TraceMessages { get; init; } = new();
/// <summary>
/// Gets a collection of messages helpful for debugging during development. These messages are often diagnostic.
/// </summary>
[JsonIgnore]
public List<string> DebugMessages { get; init; } = new();
/// <summary>
/// Gets a collection of informational messages, less critical than warnings, generally used for non-critical notifications.
/// </summary>
[JsonIgnore]
public List<string> InformationMessages { get; init; } = new();
/// <summary>
/// Gets a collection of messages indicating potential issues that are not necessarily errors, but which may require attention.
/// </summary>
[JsonIgnore]
public List<string> WarningMessages { get; init; } = new();
/// <summary>
/// Gets a collection of error messages indicating failures or problems within the service.
/// </summary>
[JsonIgnore]
public List<string> ErrorMessages { get; init; } = new();
/// <summary>
/// Gets a collection of messages indicating critical issues that require immediate attention.
/// </summary>
[JsonIgnore]
public List<string> CriticalMessages { get; init; } = new();
/// <summary>
/// A function that translates a message key from a string to its localized or transformed representation.
/// This property allows for custom translation logic to be applied based on the application's needs.
/// </summary>
[JsonIgnore]
public Func<string, string> KeyTranslator { get; init; } = key => key;
/// <summary>
/// Adds a new message to the collection of messages associated with the service operation.
/// </summary>
/// <param name="message">The message to add.</param>
/// <returns>The current instance of ServiceMessage, allowing for method chaining.</returns>
[Obsolete("Deprecated: Use ClientMessages instead.")]
public IServiceMessage WithMessage(string message)
{
Messages.Add(message);
@ -47,6 +120,7 @@ namespace DigitalData.Core.Application
/// </summary>
/// <param name="messageKey">The enum value representing the message key.</param>
/// <returns>The current instance of ServiceMessage, allowing for method chaining.</returns>
[Obsolete("Deprecated: Use ClientMessages instead.")]
public IServiceMessage WithMessageKey(Enum messageKey)
{
Messages.Add(messageKey.ToString());

View File

@ -0,0 +1,169 @@
using DigitalData.Core.Contracts.Application;
namespace DigitalData.Core.Application
{
/// <summary>
/// Provides extension methods for IServiceMessage to enhance the usability of service messages
/// by allowing easy addition of various types of messages including client, trace, debug, information,
/// warning, error, and critical messages. These methods support both direct messages and enum-based keys
/// for messages, facilitating localized or custom-formatted messages.
/// </summary>
public static class ServiceMessageExtensions
{
#region ClientMessage
/// <summary>
/// Adds a single client message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithClientMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.ClientMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds a client message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithClientMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithClientMessage(message);
}
#endregion
#region TraceMessages
/// <summary>
/// Adds a trace message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The trace message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithTraceMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.TraceMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds a trace message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the trace message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithTraceMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithTraceMessage(message);
}
#endregion
#region DebugMessages
/// <summary>
/// Adds a debug message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The debug message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithDebugMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.DebugMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds a debug message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the debug message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithDebugMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithDebugMessage(message);
}
#endregion
#region WarningMessages
/// <summary>
/// Adds a warning message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The warning message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithWarningMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.WarningMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds a warning message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the warning message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithWarningMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithWarningMessage(message);
}
#endregion
#region ErrorMessages
/// <summary>
/// Adds an error message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The error message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithErrorMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.ErrorMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds an error message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the error message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithErrorMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithErrorMessage(message);
}
#endregion
#region CriticalMessages
/// <summary>
/// Adds a critical message to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="message">The critical message to add.</param>
/// <returns>The modified service message instance.</returns>
public static T WithCriticalMessage<T>(this T serviceMessage, string message) where T : IServiceMessage
{
serviceMessage.CriticalMessages.Add(message);
return serviceMessage;
}
/// <summary>
/// Adds a critical message based on an enumeration key to the service message.
/// </summary>
/// <param name="serviceMessage">The service message to modify.</param>
/// <param name="messageKey">The enum key representing the critical message.</param>
/// <returns>The modified service message instance.</returns>
public static T WithCriticalMessageKey<T>(this T serviceMessage, Enum messageKey) where T : IServiceMessage
{
var message = serviceMessage.KeyTranslator(messageKey.ToString());
return serviceMessage.WithCriticalMessage(message);
}
#endregion
}
}

View File

@ -9,17 +9,47 @@ namespace DigitalData.Core.Application
/// <typeparam name="T">The type of data returned by the service operation, if any.</typeparam>
public class ServiceResult<T> : ServiceMessage, IServiceResult<T>
{
/// <summary>
/// Initializes a new instance of the ServiceResult class.
public ServiceResult()
{
}
/// <summary>
/// Initializes a new instance of the ServiceResult class, specifying the success status is false and data.
/// Optionally, a function for translating message keys can be provided.
/// If a translation function is provided, it will be used for both string and enum message keys.
/// </summary>
/// <param name="data">The data associated with a successful operation.</param>
/// <param name="stringKeyTranslator">A function that translates a string key into its localized representation.
/// If provided, it will also be adapted for translating enum keys by converting them to strings first.</param>
[Obsolete("Deprecated: initialize objects using object initializers instead.")]
public ServiceResult(T? data)
{
Data = data;
IsSuccess = false;
}
/// <summary>
/// Initializes a new instance of the ServiceResult class with specified success status and data.
/// </summary>
/// <param name="data">The data associated with a successful operation.</param>
/// <param name="isSuccess">Indicates whether the service operation was successful.</param>
[Obsolete("Deprecated: initialize objects using object initializers instead.")]
public ServiceResult(T? data, bool isSuccess) : base(isSuccess) => Data = data;
/// <summary>
/// Initializes a new instance of the ServiceResult class with specified success status, data, and messages.
/// </summary>
/// <param name="data">The data associated with a successful operation.</param>
/// <param name="isSuccess">Indicates whether the service operation was successful.</param>
/// <param name="messages">An array of messages related to the operation's outcome.</param>
[Obsolete("Deprecated: Use ClientMessages instead.")]
public ServiceResult(T? data, bool isSuccess, params string[] messages) : base(isSuccess, messages) => Data = data;
/// <summary>
/// Gets or sets the data resulting from the service operation.
/// </summary>
public T? Data { get; set; }
public T? Data { get; set; } = default;
}
}

View File

@ -1 +1 @@
3640b57401dc921b27e40c7f798bc080351d913f
1204f54a36145ece1945026f8fb6c0371ee8b734

View File

@ -5,62 +5,70 @@ 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 flag indicating whether the service operation was successful.
/// 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 intended for client display. This is intended to replace the deprecated 'Messages' property.
/// </summary>
List<string> ClientMessages { get; set; }
/// <summary>
/// [Obsolete("Deprecated: Use ClientMessages instead.")]
/// Gets or sets a collection of messages associated with the service operation. These messages can be error descriptions,
/// 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.")]
List<string> Messages { get; set; }
List<string> Messages { get; init; }
/// <summary>
/// Gets or sets a collection of messages used for tracing program execution at a fine-grained level. These are typically voluminous and detailed.
/// Gets a collection of messages intended for client display. This replaces the deprecated 'Messages' property.
/// </summary>
[JsonIgnore]
List<string> TraceMessages { get; set; }
List<string> ClientMessages { get; init; }
/// <summary>
/// Gets or sets a collection of messages helpful for debugging during development. These messages are often diagnostic.
/// Gets a collection of messages used for tracing program execution at a fine-grained level. These are typically voluminous and detailed.
/// </summary>
[JsonIgnore]
List<string> DebugMessages { get; set; }
List<string> TraceMessages { get; init; }
/// <summary>
/// Gets or sets a collection of informational messages, less critical than warnings, generally used for non-critical notifications.
/// Gets a collection of messages helpful for debugging during development. These messages are often diagnostic.
/// </summary>
[JsonIgnore]
List<string> InformationMessages { get; set; }
List<string> DebugMessages { get; init; }
/// <summary>
/// Gets or sets a collection of messages indicating potential issues that are not necessarily errors, but which may require attention.
/// Gets a collection of informational messages, less critical than warnings, generally used for non-critical notifications.
/// </summary>
[JsonIgnore]
List<string> WarningMessages { get; set; }
List<string> InformationMessages { get; init; }
/// <summary>
/// Gets or sets a collection of error messages indicating failures or problems within the service.
/// Gets a collection of messages indicating potential issues that are not necessarily errors, but which may require attention.
/// </summary>
[JsonIgnore]
List<string> ErrorMessages { get; set; }
List<string> WarningMessages { get; init; }
/// <summary>
/// Gets or sets a collection of messages indicating critical issues that require immediate attention.
/// Gets a collection of error messages indicating failures or problems within the service.
/// </summary>
[JsonIgnore]
List<string> CriticalMessages { get; set; }
List<string> ErrorMessages { get; init; }
/// <summary>
/// Gets a collection of messages indicating critical issues that require immediate attention.
/// </summary>
[JsonIgnore]
List<string> CriticalMessages { get; init; }
/// <summary>
/// A function that translates a message key from a string to its localized or transformed representation.
/// This property allows for custom translation logic to be applied based on the application's needs.
/// </summary>
[JsonIgnore]
public Func<string, string> KeyTranslator { get; init; }
/// <summary>
/// Adds a new message to the appropriate collection based on the message type.