fl-shared-utils-mappers 0.2.1

dotnet add package fl-shared-utils-mappers --version 0.2.1
                    
NuGet\Install-Package fl-shared-utils-mappers -Version 0.2.1
                    
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="fl-shared-utils-mappers" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="fl-shared-utils-mappers" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="fl-shared-utils-mappers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add fl-shared-utils-mappers --version 0.2.1
                    
#r "nuget: fl-shared-utils-mappers, 0.2.1"
                    
#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.
#:package fl-shared-utils-mappers@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=fl-shared-utils-mappers&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=fl-shared-utils-mappers&version=0.2.1
                    
Install as a Cake Tool

Fl.Shared.Utils.Mappers

Shared mapper library for .NET web applications. Provides generic mapping abstractions and a ready-made implementation that converts functional types (Option, Error) into ASP.NET Core IResult HTTP responses.


Project structure

Fl.Shared.Utils.Mappers/
├── IMapper.cs
├── IApiResultMapper.cs
└── DataHttpContentMapper.cs

Interfaces

IMapper<T1, T2>

Generic mapping contract between two types.

public interface IMapper<in T1, out T2>
{
    T2 Map(T1 item);
}

Use this interface to define any single-direction mapping between an input type T1 and an output type T2.


IApiResultMapper<T>

Specialisation of IMapper for mapping API results to ASP.NET Core IResult. Combines two mapping contracts:

  • IMapper<Option<T>, IResult> — maps an optional value to an HTTP response
  • IMapper<Error, IResult> — maps a functional error to an HTTP response
public interface IApiResultMapper<T> :
    IMapper<Option<T>, IResult>,
    IMapper<Error, IResult>
{ }

Implementations

DataHttpContentMapper<T>

Default implementation of IApiResultMapper<T>. Maps Option<T> and Error values to JSON IResult responses with appropriate HTTP status codes.

Input HTTP status Response body
Option<T>.Some(value) 200 OK JSON-serialised value
Option<T>.None 404 Not Found { "message": "Not Found" }
Error 500 Internal Server Error { "message": "Internal Server Error" }

Error responses use ErrorResponse (from Fl.Shared.Utils.Components.Web.Models) with the reason phrase derived from the HTTP status code.

Usage
// Register in DI
services.AddSingleton<IApiResultMapper<MyDto>, DataHttpContentMapper<MyDto>>();

// Use in a minimal API endpoint
app.MapGet("/items/{id}", async (int id, IApiResultMapper<MyDto> mapper, IMyService service) =>
{
    Option<MyDto> result = await service.GetById(id);
    return mapper.Map(result);
});

Tests

Unit tests are located in tests/Fl.Shared.Utils.Mappers.Tests and cover:

Class under test Scenarios
DataHttpContentMapper<T> Error input → 500 JSON with "Internal Server Error"
DataHttpContentMapper<T> Option.None input → 404 JSON with "Not Found"
DataHttpContentMapper<T> Option.Some(value) input → 200 JSON with the original value

Main dependencies

  • LanguageExt — functional types (Option, Error)
  • Microsoft.AspNetCore.AppIResult, Results, StatusCodes
  • Fl.Functional.Utils — functional utilities (Map, etc.)
  • Fl.Shared.Utils.Components.Web.ModelsErrorResponse
Product 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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.2.1 158 4/30/2026
0.2.0 258 3/1/2026
0.1.0 110 3/1/2026