Myce.Response
1.0.5
dotnet add package Myce.Response --version 1.0.5
NuGet\Install-Package Myce.Response -Version 1.0.5
<PackageReference Include="Myce.Response" Version="1.0.5" />
<PackageVersion Include="Myce.Response" Version="1.0.5" />
<PackageReference Include="Myce.Response" />
paket add Myce.Response --version 1.0.5
#r "nuget: Myce.Response, 1.0.5"
#:package Myce.Response@1.0.5
#addin nuget:?package=Myce.Response&version=1.0.5
#tool nuget:?package=Myce.Response&version=1.0.5
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.
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<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);
}
- 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
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.
| 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 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. |
| .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.2)
- System.Text.Json (>= 10.0.3)
-
net6.0
- Myce.Extensions (>= 1.0.2)
- System.Text.Json (>= 10.0.3)
-
net7.0
- Myce.Extensions (>= 1.0.2)
- System.Text.Json (>= 10.0.3)
-
net8.0
- Myce.Extensions (>= 1.0.2)
- System.Text.Json (>= 10.0.3)
-
net9.0
- Myce.Extensions (>= 1.0.2)
- System.Text.Json (>= 10.0.3)
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.