Notim.Outputs 3.0.0

dotnet add package Notim.Outputs --version 3.0.0                
NuGet\Install-Package Notim.Outputs -Version 3.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="Notim.Outputs" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Notim.Outputs --version 3.0.0                
#r "nuget: Notim.Outputs, 3.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.
// Install Notim.Outputs as a Cake Addin
#addin nuget:?package=Notim.Outputs&version=3.0.0

// Install Notim.Outputs as a Cake Tool
#tool nuget:?package=Notim.Outputs&version=3.0.0                

Notim.Outputs

.Net Tests passed NuGet Downloads

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 3.0.0

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 not Good) {
  output.AddFaultMessage("something is not good");
}
else{
  output.AddMessage("Success");
  output.AddResult(new ClassThatYouNeedToTransport(argsThenYouNeed));
}

return output;

Faults treatment by Fault type

you have the functionality to determine the Fault 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 not Good && externalServiceIsOffline)
{
  output.AddFault(new Fault(FaultType.ExternalServiceUnavailable, "customer service is down"));
}
else if (something is not Good && cannotFindResultOnDatabase)
{
  output.AddFault(new Fault(FaultType.ResourceNotFound, "the user with id xxx cannot be find"));
}
else if (something is not Good && invalidInputReceived)
{
  output.AddFault(new Fault(FaultType.InvalidInput, "invalid fields"));
}
else
{
  output.AddMessage("Success");
  output.AddResult(new ClassThatYouNeedToTransport(argsThenYouNeed));
}

return output;

Asp .Net WebApi Controller using "use case" pattern example:

[HttpGet("/")]
public async Task<IActionResult> GetOrder(ClassThatYouReceiveDataInput input, CancelationToken cancelationToken)

    Output<ClassThatYouNeedToTransport> output = await _findUserByIdUseCase.Handle(input, cancelationToken);
    
    if (!output.IsValid && output.Fault?.FaultType  is FaultType.ExternalServiceUnavailable)
        return BadGateway(output.Fault);
    
    if (!output.IsValid && output.Fault?.FaultType is FaultType.ResourceNotFound)
        return NotFound(output.Fault);
    
    if (!output.IsValid && output.Fault?.FaultType is FaultType.InvalidInput)
        return UnprocessableEntity(output.Fault);
    
    if (!output.IsValid && output.Fault?.FaultType is FaultType.InvalidOperation)
        return UnprocessableEntity(output.Fault);
    
    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());

Fault use case output

var output = Output<ClassThatYouNeedToTransport>.WithFault("An Fault was ocurred");

Fault object use case output

var output = Output<ClassThatYouNeedToTransport>.WithFault(new Fault(FaultType.ExternalServiceUnavailable, "external service is unavaiable"));

Empty body can be returned

After version 3 you can use the Output with empty body to create Output
var output = Output();
output.AddFault("simple error");
var output = Output();
output.AddFault(new Fault(ErrorType.ExternalServiceUnavailable), "external error");

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 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. 
.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.
  • net8.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 707 3/5/2024
2.0.3 323 11/8/2023
2.0.2 693 11/8/2023
2.0.1 156 11/7/2023
2.0.0 132 11/7/2023
1.0.2 161 11/7/2023
1.0.1 161 11/7/2023
1.0.0 200 11/7/2023