Myce.Response 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Myce.Response --version 1.0.0
                    
NuGet\Install-Package Myce.Response -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Myce.Response" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Myce.Response" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Myce.Response" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Myce.Response --version 1.0.0
                    
#r "nuget: Myce.Response, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Myce.Response@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Myce.Response&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Myce.Response&version=1.0.0
                    
Install as a Cake Tool

Myce.Response

A lightweight and robust .NET library implementing the Result Pattern to standardize API responses, handle business logic flow, and manage complex messaging with frontend-driven internationalization support.

Features

  • Unified Result Envelope: Standardized Result and Result<T> classes for consistent API contracts.

  • Rich Messaging System: Support for multiple message types (Information, Warning, Error).

  • Dynamic Variable Interpolation: Messages support placeholders (using {} or []) for runtime data injection.

  • Frontend-Ready i18n: Messages carry unique codes and variable dictionaries, allowing the frontend to handle translations.

  • Lean Payloads: Internal logic properties are marked with [JsonIgnore] to keep JSON responses small and efficient.

  • Smart Fallback: The Title property automatically defaults to the text of the first message if not explicitly set.


Installation

dotnet add package Myce.Response

Usage

  1. Basic Result

Use the Result class for operations that report status without returning a data payload.

public Result UpdateSystemSetting(string key, string value)
{
  if (string.IsNullOrEmpty(key))
   return Result.Failure(new ErrorMessage("KEY_REQUIRED", "Setting key is mandatory"));
 
  // Business logic execution...
  return Result.Success("Setting updated successfully");
}
  1. Returning Data with Result<T>

Use Result<T> to wrap the return value of your services.

public Result<User> GetUser(int id)
{
    var user = _repository.Find(id);
    
    if (user == null)
        return Result<User>.Failure(new ErrorMessage("USER_NOT_FOUND", "The requested user does not exist"));

    return Result<User>.Success(user);
}
  1. Messaging with Variables (i18n Support)

Placeholders in messages allow the frontend to perform translation using a dictionary while maintaining dynamic context.

var message = new ErrorMessage("INSUFFICIENT_FUNDS", "You need at least {Required} to complete this, but you have {Current}");
message.AddVariable("Required", "50.00");
message.AddVariable("Current", "10.50");

return Result.Failure(message);

Architecture

The Result Object

  • Title: (string) A high-level summary. If null, it returns Messages.FirstOrDefault()?.Text.
  • IsValid: (bool) Returns true only if no ErrorMessage is present.
  • Messages: (IReadOnlyCollection) A list of Information, Warning, or Error objects.
  • Data: (T) The generic payload (specific to Result<T>).

Message Types

  1. InformationMessage: Used for non-critical status updates.
  2. WarningMessage: Used for alerts that do not block the operation.
  3. ErrorMessage: Critical failures. Presence of this type makes IsValid return false.

Frontend Integration (Internationalization)

This library follows a Client-Side Translation strategy. The backend provides the structural data, and the frontend applies the locale based on the Code. | Property | Purpose |Example| |--|--|--| |Code|Unique translation key|"VALIDATION_ERROR"| | Text | Default fallback (English) |"Invalid input"| |Variables|Key-value pairs for interpolation|[{"Name": "Field", "Value": "Email"}]|

Best Practices

  1. Explicit Titles: Set the Title property when you want a specific summary for the UI that differs from individual error messages.

  2. Controller Mapping: Use the ToActionResult() extension to automatically map your Result to the appropriate HTTP status code (200 OK, 204 No Content, 400 Bad Request, or 404 Not Found).

  3. ToResult Mapping: Use .ToResult<V>(map) to convert between types (e.g., Entity to DTO) while preserving all messages and state.

    [HttpGet("{id}")] public IActionResult Get(int id) ⇒ _userService.GetById(id).ToActionResult();

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Myce.Response:

Package Downloads
Myce.FluentValidator

MYCE (Makes Your Coding Easier) FluentValidator is fluent validation class

Myce.Validation

MYCE (Makes Your Coding Easier) Validation is fluent validation class

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 39 3/12/2026
1.0.4 113 3/7/2026
1.0.3 297 2/23/2026
1.0.1 138 2/12/2026
1.0.0 103 2/7/2026
0.1.2 440 3/29/2023
0.1.1 455 1/21/2023
0.1.0 356 1/21/2023