FunctionalDdd.Asp
2.0.0-alpha.47
See the version list below for details.
dotnet add package FunctionalDdd.Asp --version 2.0.0-alpha.47
NuGet\Install-Package FunctionalDdd.Asp -Version 2.0.0-alpha.47
<PackageReference Include="FunctionalDdd.Asp" Version="2.0.0-alpha.47" />
paket add FunctionalDdd.Asp --version 2.0.0-alpha.47
#r "nuget: FunctionalDdd.Asp, 2.0.0-alpha.47"
// Install FunctionalDdd.Asp as a Cake Addin #addin nuget:?package=FunctionalDdd.Asp&version=2.0.0-alpha.47&prerelease // Install FunctionalDdd.Asp as a Cake Tool #tool nuget:?package=FunctionalDdd.Asp&version=2.0.0-alpha.47&prerelease
ASP Extension
This library will help convert Error objects to ASP.NET Core ActionResult
MVC
- ToOkActionResult
- ToErrorActionResult
ToOkActionResult
Use this method to convert Result
to OkObjectResult
or various failed results.
ToErrorActionResult
Use this method to convert Error
to various failed results.
The mapping is as follows
NotFoundError => (ActionResult<T>)controllerBase.NotFound(error),
ValidationError validation => ValidationErrors<T>(validation, controllerBase),
ConflictError => (ActionResult<T>)controllerBase.Conflict(error),
UnauthorizedError => (ActionResult<T>)controllerBase.Unauthorized(error),
ForbiddenError => (ActionResult<T>)controllerBase.StatusCode(StatusCodes.Status403Forbidden, error),
UnexpectedError => (ActionResult<TValue>)controllerBase.StatusCode(StatusCodes.Status500InternalServerError, error),
_ => (ActionResult<TValue>)controllerBase.StatusCode(StatusCodes.Status500InternalServerError, error),
Example
Simple case.
[HttpPost("[action]")]
public ActionResult<User> Register([FromBody] RegisterRequest request) =>
FirstName.TryCreate(request.firstName)
.Combine(LastName.TryCreate(request.lastName))
.Combine(EmailAddress.TryCreate(request.email))
.Bind((firstName, lastName, email) => SampleWebApplication.User.TryCreate(firstName, lastName, email, request.password))
.ToOkActionResult(this);
To control the return type
[HttpPost("[action]")]
public ActionResult<User> RegisterCreated2([FromBody] RegisterRequest request) =>
FirstName.TryCreate(request.firstName)
.Combine(LastName.TryCreate(request.lastName))
.Combine(EmailAddress.TryCreate(request.email))
.Bind((firstName, lastName, email) => SampleWebApplication.User.TryCreate(firstName, lastName, email, request.password))
.Finally(
ok => CreatedAtAction("Get", new { name = ok.FirstName }, ok),
err => err.ToErrorActionResult<User>(this));
ToPartialOrOkActionResult
ToPartialOrOkActionResult can be used to support pagination. The function takes in three parameters to, from and length and based on the values will return PartialContent (206) or Okay(200) per RFC9110
Minimal API
- ToOkResult
- ToErrorResult
ToOkResult
Use this method to convert Result
to IResult
or various failed results.
ToErrorResult
Use this method to convert Error
to various failed results.
Example
Simple case.
userApi.MapPost("/register", (RegisterUserRequest request) =>
FirstName.TryCreate(request.firstName)
.Combine(LastName.TryCreate(request.lastName))
.Combine(EmailAddress.TryCreate(request.email))
.Bind((firstName, lastName, email) => User.TryCreate(firstName, lastName, email, request.password))
.ToOkResult());
To control the return type
userApi.MapPost("/registerCreated", (RegisterUserRequest request) =>
FirstName.TryCreate(request.firstName)
.Combine(LastName.TryCreate(request.lastName))
.Combine(EmailAddress.TryCreate(request.email))
.Bind((firstName, lastName, email) => User.TryCreate(firstName, lastName, email, request.password))
.Map(user => new RegisterUserResponse(user.Id, user.FirstName, user.LastName, user.Email, user.Password))
.Finally(
ok => Results.CreatedAtRoute("GetUserById", new RouteValueDictionary { { "name", ok.firstName } }, ok),
err => err.ToErrorResult()));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- FunctionalDdd.RailwayOrientedProgramming (>= 2.0.0-alpha.47)
- Microsoft.Extensions.DependencyModel (>= 8.0.2)
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 |
---|---|---|
2.0.0-alpha.52 | 43 | 11/7/2024 |
2.0.0-alpha.48 | 42 | 11/2/2024 |
2.0.0-alpha.47 | 41 | 10/30/2024 |
2.0.0-alpha.44 | 100 | 10/18/2024 |
2.0.0-alpha.42 | 51 | 10/14/2024 |
2.0.0-alpha.39 | 73 | 6/27/2024 |
2.0.0-alpha.38 | 70 | 4/24/2024 |
2.0.0-alpha.33 | 64 | 4/17/2024 |
2.0.0-alpha.26 | 85 | 4/9/2024 |
2.0.0-alpha.21 | 85 | 4/1/2024 |
2.0.0-alpha.19 | 68 | 3/5/2024 |
2.0.0-alpha.18 | 67 | 2/28/2024 |
2.0.0-alpha.17 | 61 | 2/26/2024 |
2.0.0-alpha.15 | 88 | 1/30/2024 |
2.0.0-alpha.8 | 68 | 1/27/2024 |
2.0.0-alpha.6 | 104 | 1/5/2024 |
1.1.1 | 581 | 11/15/2023 |
1.1.0-alpha.32 | 120 | 11/2/2023 |
1.1.0-alpha.30 | 212 | 10/31/2023 |
1.1.0-alpha.28 | 90 | 10/28/2023 |
1.1.0-alpha.27 | 84 | 10/28/2023 |
1.1.0-alpha.24 | 86 | 10/20/2023 |
1.1.0-alpha.23 | 85 | 10/13/2023 |
1.1.0-alpha.22 | 87 | 10/13/2023 |
1.1.0-alpha.21 | 100 | 10/1/2023 |
1.1.0-alpha.20 | 89 | 9/30/2023 |
1.1.0-alpha.19 | 97 | 9/30/2023 |
1.1.0-alpha.18 | 95 | 9/29/2023 |
1.1.0-alpha.17 | 83 | 9/22/2023 |
1.1.0-alpha.13 | 90 | 9/16/2023 |
1.1.0-alpha.4 | 130 | 6/9/2023 |
1.1.0-alpha.3 | 79 | 6/8/2023 |
1.0.1 | 590 | 5/12/2023 |
0.1.0-alpha.40 | 123 | 4/6/2023 |
0.1.0-alpha.39 | 115 | 4/3/2023 |
0.1.0-alpha.38 | 152 | 4/2/2023 |
0.1.0-alpha.37 | 123 | 3/31/2023 |
0.1.0-alpha.35 | 120 | 3/29/2023 |
0.1.0-alpha.34 | 106 | 3/28/2023 |
0.1.0-alpha.32 | 142 | 3/18/2023 |
0.1.0-alpha.30 | 133 | 3/11/2023 |
0.1.0-alpha.27 | 135 | 3/7/2023 |
0.1.0-alpha.24 | 136 | 2/15/2023 |
0.1.0-alpha.22 | 125 | 2/15/2023 |
0.1.0-alpha.20 | 133 | 2/13/2023 |
0.1.0-alpha.19 | 92 | 2/13/2023 |
0.0.1-alpha.14 | 147 | 1/4/2023 |
0.0.1-alpha.4 | 131 | 12/30/2022 |
0.0.1-alpha.3 | 148 | 12/23/2022 |
0.0.1-alpha | 542 | 12/21/2022 |