Myce.Response
1.5.1
dotnet add package Myce.Response --version 1.5.1
NuGet\Install-Package Myce.Response -Version 1.5.1
<PackageReference Include="Myce.Response" Version="1.5.1" />
<PackageVersion Include="Myce.Response" Version="1.5.1" />
<PackageReference Include="Myce.Response" />
paket add Myce.Response --version 1.5.1
#r "nuget: Myce.Response, 1.5.1"
#:package Myce.Response@1.5.1
#addin nuget:?package=Myce.Response&version=1.5.1
#tool nuget:?package=Myce.Response&version=1.5.1
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.
Supports net6.0, net7.0, net8.0, net9.0, and netstandard2.0.
Features
- Unified Result Envelope: Standardized
ResultandResult<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
Titleproperty automatically defaults to the text of the first message if not explicitly set. - Merge: Easily combine results between types while preserving messages.
Installation
dotnet add package Myce.Response
Usage
- 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");
}
- Returning Data with Result
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);
}
- 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);
- Backend-Driven Multilingual Messaging
You can store multiple translations directly within the message on the backend and resolve them dynamically using the .Show(language) method.
Option A: Using dictionaries (Bulk initialization)
var templates = new Dictionary<string, string>
{
{ "en-US", "The field {fieldName} must be today." },
{ "pt-BR", "O campo {fieldName} deve ser a data de hoje." }
};
var fieldTranslations = new Dictionary<string, string>
{
{ "en-US", "Birth Date" },
{ "pt-BR", "Data de Nascimento" }
};
var message = new ErrorMessage("DATETIME_IS_TODAY", templates);
message.AddVariableMultilingual("fieldName", fieldTranslations);
// Resolve dynamically based on the client's language
string enOutput = message.Show("en-US"); // "The field Birth Date must be today."
string ptOutput = message.Show("pt-BR"); // "O campo Data de Nascimento deve ser a data de hoje."
Option B: Incremental configuration (Individual translations)
var message = new ErrorMessage(MessageType.Error);
message.Code = "INVALID_FIELD";
// Add text templates individually
message.AddTextTranslation("en-US", "The {fieldName} is invalid.");
message.AddTextTranslation("pt-BR", "O {fieldName} é inválido.");
// Add variable translations individually
message.AddVariableTranslation("fieldName", "en-US", "Email Address");
message.AddVariableTranslation("fieldName", "pt-BR", "Endereço de E-mail");
string result = message.Show("pt-BR"); // "O Endereço de E-mail é inválido."
Architecture
The Result Object
- Title: (string) A high-level summary. If null, it returns
Messages.FirstOrDefault()?.Text. - IsSuccess: (bool) Returns
trueonly if noErrorMessageis present. - Messages: (IReadOnlyCollection) A list of
Information,Warning, orErrorobjects. - Data: (T) The generic payload (specific to
Result<T>).
Message Types
- InformationMessage: Used for non-critical status updates.
- WarningMessage: Used for alerts that do not block the operation.
- ErrorMessage: Critical failures. Presence of this type makes
IsValidreturnfalse.
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
- Explicit Titles: Set the
Titleproperty when you want a specific summary for the UI that differs from individual error messages. - ToResult Mapping: Use
.ToResult<V>(map)to convert between types (e.g., Entity to DTO) while preserving all messages and state.
Notes
Version 1.5.0
- Add internationalization support for Message class.
Version 1.3.0
- Remove obsolete attribute IsValid (was replaced by IsSuccess).
Version 1.2.0
- Introduces support for
net10.0, ensuring compatibility with the latest .NET features and improvements.
Version 1.0.0
- The initial stable release of Myce.Response, providing basic response handling capabilities for .NET applications.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
-
net10.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
-
net6.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
-
net7.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
-
net8.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
-
net9.0
- Myce.Extensions (>= 1.0.3)
- System.Text.Json (>= 11.0.0-preview.5.26302.115)
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.5.1 | 38 | 6/27/2026 |
| 1.5.0 | 50 | 6/27/2026 |
| 1.3.3 | 365 | 4/19/2026 |
| 1.3.2 | 115 | 4/16/2026 |
| 1.3.1 | 151 | 4/16/2026 |
| 1.3.0 | 116 | 4/16/2026 |
| 1.1.0 | 159 | 3/17/2026 |
| 1.0.5 | 239 | 3/12/2026 |
| 1.0.4 | 151 | 3/7/2026 |
| 1.0.3 | 325 | 2/23/2026 |
| 1.0.1 | 162 | 2/12/2026 |
| 1.0.0 | 130 | 2/7/2026 |
| 0.1.2 | 456 | 3/29/2023 |
| 0.1.1 | 475 | 1/21/2023 |
| 0.1.0 | 371 | 1/21/2023 |