Fügen Sie 'ohne Nachricht' Methoden in ResponseService hinzu

Implementieren und dokumentieren Sie Dienstmethoden, die ohne zusätzliche Nachrichten funktionieren, um die Einfachheit der Schnittstelle zu verbessern.
This commit is contained in:
Developer 02 2024-04-18 14:29:11 +02:00
parent 7b0ef9b0c2
commit c350c63b1f
38 changed files with 112 additions and 9 deletions

Binary file not shown.

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Contracts.Application;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace DigitalData.Core.Application
{
@ -7,16 +8,64 @@ namespace DigitalData.Core.Application
/// </summary>
public class ResponseService : IResponseService
{
#region WITHOUT_MESSAGE
/// <summary>
/// Creates a service message indicating success or failure without additional messages.
/// </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);
/// <summary>
/// Creates a service result containing the provided data and a success flag, without additional messages.
/// </summary>
/// <typeparam name="T">The type of the data included in the result.</typeparam>
/// <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);
/// <summary>
/// Creates a service message indicating a successful operation without additional messages.
/// </summary>
/// <returns>A service message indicating a successful operation.</returns>
public IServiceMessage Successful() => CreateMessage(true);
/// <summary>
/// Creates a service message indicating a failed operation without additional messages.
/// </summary>
/// <returns>A service message indicating a failed operation.</returns>
public IServiceMessage Failed() => CreateMessage(false);
/// <summary>
/// Creates a successful service result with the specified data, without additional messages.
/// </summary>
/// <typeparam name="T">The type of data included in the result.</typeparam>
/// <param name="data">The data to include in the result.</param>
/// <returns>A successful service result containing the specified data.</returns>
public IServiceResult<T> Successful<T>(T data) => CreateResult(data, true);
/// <summary>
/// Creates a failed service result with optional data, without additional messages.
/// </summary>
/// <typeparam name="T">The type of data the service result can contain.</typeparam>
/// <param name="data">Optional data to include in the result.</param>
/// <returns>A failed service result, which may or may not contain the specified data.</returns>
public IServiceResult<T> Failed<T>(T? data = default) => CreateResult(data, false);
#endregion
#region WITH_STRING_MESSAGE
/// <summary>
/// Creates a service message with the specified success flag and messages.
/// </summary>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <param name="messages">An array of messages associated with the operation.</param>
/// <returns>A new instance of <see cref="ServiceMessage"/> reflecting the operation outcome.</returns>
public virtual IServiceMessage CreateMessage(bool isSuccess, params string[] messages)
{
return new ServiceMessage(isSuccess, messages);
}
public virtual IServiceMessage CreateMessage(bool isSuccess, params string[] messages) => new ServiceMessage(isSuccess, messages);
/// <summary>
/// Creates a service result containing the provided data, success flag, and messages.
@ -26,10 +75,7 @@ namespace DigitalData.Core.Application
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <param name="messages">An array of messages associated with the operation.</param>
/// <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)
{
return new ServiceResult<T>(data, isSuccess, messages);
}
public virtual IServiceResult<T> CreateResult<T>(T? data = default, bool isSuccess = true, params string[] messages) => new ServiceResult<T>(data, isSuccess, messages);
/// <summary>
/// Creates a successful service message.
@ -76,6 +122,9 @@ namespace DigitalData.Core.Application
/// and it will include the provided failure messages.</returns>
public virtual IServiceResult<T> Failed<T>(params string[] messages) => Failed<T>(default, messages);
#endregion
#region WITH_ENUM_MESSAGE
/// <summary>
/// Creates a service message with the specified success flag and enumeration messages.
/// </summary>
@ -134,5 +183,7 @@ namespace DigitalData.Core.Application
/// <returns>A failed service result. The data part of the result will be set to the default value for the specified type,
/// and it will include the provided failure messages.</returns>
public IServiceResult<T> Failed<T>(params Enum[] messages) => Failed<T>(default(T), messages);
#endregion
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@ -45,7 +45,6 @@ E:\TekH\Visual Studio\DDWeb\WebCoreModules\DigitalData.Core.Application\obj\Debu
E:\TekH\Visual Studio\DDWeb\WebCoreModules\DigitalData.Core.Application\obj\Debug\net7.0\refint\DigitalData.Core.Application.dll
E:\TekH\Visual Studio\DDWeb\WebCoreModules\DigitalData.Core.Application\obj\Debug\net7.0\DigitalData.Core.Application.pdb
E:\TekH\Visual Studio\DDWeb\WebCoreModules\DigitalData.Core.Application\obj\Debug\net7.0\ref\DigitalData.Core.Application.dll
E:\TekH\Visual Studio\WebCoreModules\DigitalData.Core.Application\bin\Debug\net7.0\icon.png
E:\TekH\Visual Studio\WebCoreModules\DigitalData.Core.Application\bin\Debug\net7.0\DigitalData.Core.Application.deps.json
E:\TekH\Visual Studio\WebCoreModules\DigitalData.Core.Application\bin\Debug\net7.0\DigitalData.Core.Application.dll
E:\TekH\Visual Studio\WebCoreModules\DigitalData.Core.Application\bin\Debug\net7.0\DigitalData.Core.Application.pdb

View File

@ -5,6 +5,55 @@
/// </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>
@ -67,6 +116,9 @@
/// <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>
@ -128,5 +180,6 @@
/// <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
}
}