SampleDotnet.Result 1.0.5

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

// Install SampleDotnet.Result as a Cake Tool
#tool nuget:?package=SampleDotnet.Result&version=1.0.5

Nuget CodeQL MIT

SampleDotnet.Result

Single Response Model for the ActionResult

How to Use

using SampleDotnet.Result;

Success(Status:200) ResponseModel

public IActionResult Get()
{
    List<CartDto> someResponseData = GetSomeData();
    
    return new OkResponse(someResponseData);
}

public IActionResult Get()
{
    CartDto singleData = GetSingleData();
    
    return new OkResponse(singleData);
}

NotFound(Status:404) ResponseModel

public IActionResult Get()
{
    List<CartDto> someResponseData = GetSomeData();
    
    if (someResponseData.Count == 0)
        return new NotFoundResponse($"data not found.");

    return new OkResponse(someResponseData);
}

BadRequest(Status:400) ResponseModel

public IActionResult Get(string search)
{
    if (string.NullOrEmpty(search))
        return new BadRequestResponse($"search value cannot be empty.");
        
    List<CartDto> someResponseData = GetSomeData();

    return new OkResponse(someResponseData);
}

Serialized response model

{
    "results": [
        {
            // item 1
        },        
        {
            // item 2
        }
    ],
    "errors": [ 
        "errorMessage 1",
        "errorMessage 2"
    ],
    "stats": {
        "rid": "487f53e7c8316222f52c52ffe98ff5d7", // feature: unique request tracking id
        "offset": 1676841345, // feature: measured response time
        "elapsedmilliseconds": "342.8" // feature: measured response time
    }
}

Additional Feature

  • customizable SerializerSettings for each model
  • Executor on before response model serialization
    • custom executor can be defined

pre-defined executors

  • Unique request tracking id
 // defined in ConfigureServices(IServiceCollection services)
services.AddSingleton<IBaseResultExecutor, ExecuteRequestTrackingId>();
  • Measured response time
// defined in ConfigureServices(IServiceCollection services)
services.AddSingleton<IBaseResultExecutor, ExecuteMeasuredResponsTime>();

 // call in Configure(IApplicationBuilder app, IWebHostEnvironment env) before any middlewares
app.UseElapsedTimeMeasurement();
  • Custom executor
    • define class which derived from SampleProject.Result.Interfaces.IBaseResultExecutor
    public class ExecuteAddVersionToResponseModel : IBaseResultExecutor
    {
        public Task OnBeforeActionResultExecutorAsync(
          HttpContext context
          , IServiceProvider serviceProvider
          , BaseJsonResult jsonResult)
        {
            return Task.Run(() =>
            {
                jsonResult.Model.Stats.version = "1.0.0";
            });
        }
    }
    
    • then add to ServiceCollection
    // defined in ConfigureServices(IServiceCollection services)
    services.AddSingleton<IBaseResultExecutor, ExecuteAddVersionToResponseModel>();
    
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.5 604 3/19/2023
1.0.2 586 2/25/2023
1.0.1 566 2/25/2023