Notim.Outputs
2.0.1
See the version list below for details.
dotnet add package Notim.Outputs --version 2.0.1
NuGet\Install-Package Notim.Outputs -Version 2.0.1
<PackageReference Include="Notim.Outputs" Version="2.0.1" />
paket add Notim.Outputs --version 2.0.1
#r "nuget: Notim.Outputs, 2.0.1"
// Install Notim.Outputs as a Cake Addin #addin nuget:?package=Notim.Outputs&version=2.0.1 // Install Notim.Outputs as a Cake Tool #tool nuget:?package=Notim.Outputs&version=2.0.1
Notim.Outputs
This is a Basic Wrapper for use case Outputs, commom used with Mediatr Output or CQRS Patterns
you can use in your project by nuget.org
you can install with nuget package manager
dotnet add package Notim.Outputs --version 2.0.1
Simple Usage
the usage is very simple, you only need to instace Output with classe that you need to transport.
var output = new Output<ClassThatYouNeedToTransport>();
if (something is notGood) {
output.AddErrorMessage("something is not good");
}
else{
output.AddMessage("Success");
output.AddResult(new ClassThatYouNeedToTransport(argsThenYouNeed));
}
return output;
Errors treatment by error type
you have the functionality to determine the error type to filter if you want to return a especific status code or retries on your topic consumers
var output = new Output<ClassThatYouNeedToTransport>();
if (something is notGood && externalServiceIsOffline)
{
output.AddError(new Error(ErrorType.ExternalServiceUnavailable, "customer service is down"));
}
else if (something is notGood && cannotFindResultOnDatabase)
{
output.AddError(new Error(ErrorType.ResourceNotFound, "the user with id xxx cannot be find"));
}
else if (something is notGood && invalidInputReceived)
{
output.AddError(new Error(ErrorType.InvalidInput, "invalid fields"));
}
else
{
output.AddMessage("Success");
output.AddResult(new ClassThatYouNeedToTransport(argsThenYouNeed));
}
return output;
controller using "use case" pattern:
[HttpGet("/")]
public async Task<IActionResult> GetOrder(ClassThatYouReceiveDataInput input, CancelationToken cancelationToken)
Output<ClassThatYouNeedToTransport> output = await _findUserByIdUseCase.Handle(input, cancelationToken);
if (!output.IsValid && output.Error.ErrorType is ErrorType.ExternalServiceUnavailable)
return BadGateway(output.ErrorMessages);
if (!output.IsValid && output.Error.ErrorType is ErrorType.ResourceNotFound)
return NotFound(output.ErrorMessages);
if (!output.IsValid && output.Error.ErrorType is ErrorType.InvalidInput)
return UnprocessableEntity(output.ErrorMessages);
return Ok(output.GetResult());
}
Single Line Fluent Form to build Output
After version 2 you can use the single line Build Form to create Output
success use case output
var output = Output<ClassThatYouNeedToTransport>.WithSuccess("use case finished with success", new ClassThatYouNeedToTransport());
error use case output
var output = Output<ClassThatYouNeedToTransport>.WithError("An error was ocurred");
error object use case output
var output = Output<ClassThatYouNeedToTransport>.WithError(new Error(ErrorType.ExternalServiceUnavailable, "external service is unavaiable"));
Notim.Outputs.FluentValidation
you can use FluentValidation library "ValidationResult" to create an Output with ErrorType.InvalidInput, you just only need to install the extension package:
you can install Notim.Outputs.FluentValidation with nuget package manager, run the command below:
dotnet add package Notim.Outputs.FluentValidation --version 2.0.1
simple usage
The usage is very simple:
IValidator<SomeClass> validator = new SomeClassValidator<SomeClass>();
var validationResult = validator.Validate(someObject);
var output = new Output<SomeClassThatUseToTransport>();
output.AddValidationResult(validationResult);
Contribution
If you would like to contribute to this project, follow these steps:
- Create a branch for your changes (
git checkout -b feature/MyFeature
) - Commit your changes (
git commit -am 'feat: add a feature'
) - Push to the branch (
git push origin feature/MyFeature
) - Open a Pull Request
some issues you can talk with me paulino.joaovitor@yahoo.com.br
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Notim.Outputs:
Package | Downloads |
---|---|
Notim.Outputs.FluentValidation
extensions to use Output with ValidationResult from Fluent Validation |
GitHub repositories
This package is not used by any popular GitHub repositories.