Notim.Outputs 2.0.1

There is a newer version of this package available.
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                
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="Notim.Outputs" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Notim.Outputs --version 2.0.1                
#r "nuget: Notim.Outputs, 2.0.1"                
#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.
// 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

.Net example event parameter

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:

nuget.org

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:

  1. Create a branch for your changes (git checkout -b feature/MyFeature)
  2. Commit your changes (git commit -am 'feat: add a feature')
  3. Push to the branch (git push origin feature/MyFeature)
  4. Open a Pull Request

some issues you can talk with me paulino.joaovitor@yahoo.com.br

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
3.0.0 704 3/5/2024
2.0.3 322 11/8/2023
2.0.2 692 11/8/2023
2.0.1 155 11/7/2023
2.0.0 131 11/7/2023
1.0.2 160 11/7/2023
1.0.1 160 11/7/2023
1.0.0 199 11/7/2023