Vertizens.SliceR.Minimal 0.4.0-rc.1

This is a prerelease version of Vertizens.SliceR.Minimal.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Vertizens.SliceR.Minimal --version 0.4.0-rc.1                
NuGet\Install-Package Vertizens.SliceR.Minimal -Version 0.4.0-rc.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="Vertizens.SliceR.Minimal" Version="0.4.0-rc.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Vertizens.SliceR.Minimal --version 0.4.0-rc.1                
#r "nuget: Vertizens.SliceR.Minimal, 0.4.0-rc.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.
// Install Vertizens.SliceR.Minimal as a Cake Addin
#addin nuget:?package=Vertizens.SliceR.Minimal&version=0.4.0-rc.1&prerelease

// Install Vertizens.SliceR.Minimal as a Cake Tool
#tool nuget:?package=Vertizens.SliceR.Minimal&version=0.4.0-rc.1&prerelease                

SliceR.Minimal

Adds to SliceR .NET Minimal API patterns for quickly adding endpoints

Getting Started

This code extends the .NET Minimal API codebase with IEndpointBuilder. The idea is to define one or more endpoints in a set of classes that can be registered with DI.

register all your IEndpointBuilder classes in your assembly with

services.AddEndpointBuilders();

In program.cs make sure to use them in your WebApplication by calling AddEndpointBuilders

var builder = WebApplication.CreateBuilder(args);

//... more code

var app = builder.Build();

//... more code

app.AddEndpointBuilders();

app.Run();

IEndpointBuilder

There are several helper extensions:
MapRootRouteGroup

public IEndpointRouteBuilder Build(IEndpointRouteBuilder builder)
{
    var rootRouteGroup = builder.MapRootRouteGroup<EntityType>();

    return builder;
}

This defines a Builder to add endpoints all with the same prefix. Overloads for group name, tag, and prefix.

Set ApiRouteGroupPrefix.Api to whatever constant you prefer on startup before building endpoints.

If you use standard Operations there are Map methods to simplify defining endpoints.
Examples are:
MapGetAsNoFilterQueryable<TDomain>
MapGetAsById<TDomain, TId>
MapGet<TRequest, TResult>
MapPostAsInsert<TDomainInsert, TDomain>
MapPost<TRequest, TResult>
MapPost<TRequest>
MapPutAsById<TDomainUpdate, TId, TDomain>
MapDeleteAsById<TDomain, TId>

ValidatedResult

If you use MapRootRouteGroup then the ValidatedResultEndpointFilter is added by default. This simply turns a ValidatedResult into an IResult for the endpoint. This means the result gets translated to what the Http result required so if you do custom things make sure you either perform a ToHttpResult() on the ValidatedResult or add the endpoint filter to the endpoint manually.

FileResponse

Use ValidatedResult<FileResponse> as the return value from a ValidatedHandler to get an endpoint to stream back a file from an endpoint.

Mapping Domain to Entity

If you use EF Core and want to have a DTO that is returned the basic scenarios are already handled by defining endpoints return the DTO type but then add the interface IDomainEntity<TEntity> to your DTO where TEntity is the entity type.

These default handlers can be registered by calling:

services.AddSliceREndpointDefaultValidatedHandlers();

The trick here is that the endpoint builders need to be registered first so the code can evaluate what default handler interfaces are being referenced. It then attempts to match the desired type to an entity, if not an entity then checks if the type implements the IDomainEntity<TEntity>. If it all matches up then a default handler can be registered.

Debugging Note:

Code was added to log to the console on startup for any handlers that don't exist. The Microsoft developer exception page doesn't help with what type is missing when it can't be found in the services collection. So its helpful to log this specific missing handler type at the beginning of the console log.

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 was computed.  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. 
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.0 101 12/7/2024
0.5.1-rc.1.1 56 12/5/2024
0.5.1-rc.1 59 11/28/2024
0.5.0-rc.1.3 58 11/25/2024
0.5.0-rc.1.2 65 11/23/2024
0.5.0-rc.1.1 63 11/23/2024
0.5.0-rc.1 62 11/22/2024
0.4.0-rc.1.2 56 11/17/2024
0.4.0-rc.1.1 58 11/16/2024
0.4.0-rc.1 60 11/15/2024
0.2.0-rc.1 72 11/11/2024
0.1.0-rc.1.1 67 11/10/2024
0.1.0-rc.1 58 11/4/2024