FluentResults.StatusCodes
1.0.1
dotnet add package FluentResults.StatusCodes --version 1.0.1
NuGet\Install-Package FluentResults.StatusCodes -Version 1.0.1
<PackageReference Include="FluentResults.StatusCodes" Version="1.0.1" />
paket add FluentResults.StatusCodes --version 1.0.1
#r "nuget: FluentResults.StatusCodes, 1.0.1"
// Install FluentResults.StatusCodes as a Cake Addin
#addin nuget:?package=FluentResults.StatusCodes&version=1.0.1
// Install FluentResults.StatusCodes as a Cake Tool
#tool nuget:?package=FluentResults.StatusCodes&version=1.0.1
FluentResults.StatusCodes
Simple status code management using FluentResults errors as validation.
Usage
Create your own errors inheriting from one of the base errors:
InvalidInputError //will produce a 400
UnauthorizedError //will produce a 403
NotFoundError //will produce a 404
BusinessValidationError //will produce a 409
Their constructors are simple strings, so you are encouraged to create your own constructors with custom logic.
public class MyCustomError : BusinessValidationError
{
public MyCustomError(string message, int value, object otherValue) : base($"{message} {value} {otherValue.ToString()}")
{
}
}
Those errors are automatically handled when you call the ValidateResult
method in your controllers, and the right error code is returned.
You can either inherit from the ResultControllerBase
or call the static method on the Result object.
- First option, inheriting controller
public class YourController : ResultControllerBase { [HttpGet] public IActionResult Get() { var result = Result.Ok(); //call your logic here return ValidateResult(result, () => Ok(), //on success () => {} //optional on failure ); } }
- Second option, no controller inheritance
public class YourController : ControllerBase { [HttpGet] public IActionResult Get() { var result = Result.Ok(); return result.Validate(() => Ok()); } }
Build and Test
Just clone and build. There are no tests at the moment. Feel free to create them 😃
Contribute
This is an OpenIATec public project. You are free to do whatever you want with it, just be cautious to not break any existing funcionality.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 | 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
- FluentResults (>= 3.12.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 1,714 | 9/13/2022 |