Byndyusoft.ModelResult
1.3.0
See the version list below for details.
dotnet add package Byndyusoft.ModelResult --version 1.3.0
NuGet\Install-Package Byndyusoft.ModelResult -Version 1.3.0
<PackageReference Include="Byndyusoft.ModelResult" Version="1.3.0" />
paket add Byndyusoft.ModelResult --version 1.3.0
#r "nuget: Byndyusoft.ModelResult, 1.3.0"
// Install Byndyusoft.ModelResult as a Cake Addin #addin nuget:?package=Byndyusoft.ModelResult&version=1.3.0 // Install Byndyusoft.ModelResult as a Cake Tool #tool nuget:?package=Byndyusoft.ModelResult&version=1.3.0
Byndyusoft.ModelResult
The result of domain logic, similar to ActionResult
Byndyusoft.ModelResult | ||
Byndyusoft.ModelResult.AspNetCore |
Installing
dotnet add package Byndyusoft.ModelResult
Usage
ModelResult can be used to return either an "ok" value or an "error" value without explicit casting. Here are some usage examples:
public ModelResult<int> GetId(SampleEntity entity)
{
if (entity.HasId())
return entity.Id;
return new ErrorModelResult("Project.SampleEntity.NoId", "Entity does not contain Id");
}
public ModelResult ValidateEntity(SampleEntity entity)
{
var errorInfoItems = new List<ErrorInfoItem>();
if (entity.HasId() == false)
errorInfoItems.Add(new ErrorInfoItem("Id", "Entity does not contain Id"));
if (errorInfoItems.Any())
return new ErrorModelResult("Project.SampleEntity.NotValid", "There are validation errors", errorInfoItems.ToArray());
return new OkModelResult();
}
public ModelResult<EntityInfoDto> GetEntityInfoDto(SampleEntity entity)
{
ModelResult<int> idResult = GetId(entity);
if (idResult.IsError())
{
_logger.LogError("Error getting id: {@ErrorInfo}", idResult.GetError());
return idResult.AsSimple();
}
var entityInfoDto = new EntityInfoDto {Id = idResult.Result};
return entityInfoDto;
}
ModelResult.AspNetCore
A converter of ModelResult to ActionResult
Installing
dotnet add package Byndyusoft.ModelResult.AspNetCore
Usage
[HttpGet("{id:long}")]
public async Task<ActionResult<EntityInfoDto>> GetEntityInfoDto([FromRoute] long id,
[FromServices] IGetEntityInfoDtoUseCase useCase, CancellationToken cancellationToken)
{
var result = await useCase.GetAsync(id, cancellationToken);
return result.ToActionResult();
}
If result
is an "ok" result then the action method will return a message with the 200 code and the contents of the DTO. Otherwise if it is "error" result it is usually will be transformed to 400 code with error info that contains code, message and items. The current version has one exception: if an error code is equal to Byndyusoft.ModelResult.Common.CommonErrorCodes.NotFound
there will be the 404 code without any content.
Contributing
To contribute, you will need to setup your local environment, see prerequisites. For a contribution and workflow guide, see package development lifecycle.
A detailed overview on how to contribute can be found in the contributing guide.
Prerequisites
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- .NET Core (version 6.0 or higher) - Download & Install .NET Core.
Package development lifecycle
- Implement package logic in
src
- Add or adapt unit-tests in
tests
- Add or change the documentation as needed
- Open pull request for a correct branch. Target the project's
master
branch
Maintainers
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 | 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.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Byndyusoft.ModelResult:
Package | Downloads |
---|---|
Byndyusoft.ModelResult.AspNetCore
Package Description |
|
Byndyusoft.Net.YandexAuth
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.