Slices.Endpoints.Mapper 1.0.0

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

// Install Slices.Endpoints.Mapper as a Cake Tool
#tool nuget:?package=Slices.Endpoints.Mapper&version=1.0.0                

slices-endpoints-nuget

This NuGet package simplifies the implementation of minimal APIs within nested, non-static classes, making it an ideal choice for organizing endpoints in vertical slice architecture projects. It provides a clean, modular structure that enhances code organization by grouping related endpoints within feature-based classes.

Start services

app.UseSliceEndpoints(options =>
{
      options.RegisterEndpointsFromAssembly(typeof(Program).Assembly);
});

Implementations

Using IHasEndpoints interface

Being nested or implementing IFeature interface is not mandatory when using IHasEndpoints

public class CreateOrder : IFeature
{
    public record Command() : IRequest<Return<OrderId>>
    {
    };

    internal sealed class Handler : IRequestHandler<Command, Return<OrderId>>
    {
        private readonly IAppEventStore _store;

        public Handler(IAppEventStore store)
        {
            _store = store;
        }
        public async Task<Return<OrderId>> Handle(Command request, CancellationToken cancellationToken)
        {
           // Handler logic
        }
    }
    // THIS ENDPOINT WILL BE MAPPED TO THE ROUTER BY THE PACKAGE
    public class Endpoint : IHasEndpoints
    {
        public record Request()
        {
        }
        public void Map(IEndpointRouteBuilder app)
        {
            app.MapPost("api/orders", async ([FromBody] Request request, [FromServices] IMediator mediator) =>
            {
                var result = await mediator.Send(new Command());
                return result.Value;
            });
        }
    }

}

Using naming convention

MANDATORY to implement IFeature marker interface for declaring class/type of "Endpoints"

// Implementing IFeature is MUST to use naming convention.
public class CreateOrder : IFeature
{
    // Nested class should be named Endpoints
    public class Endpoints
    {
        public record Request()
        {
        }
        // Map method SHOULD accept IEndpointRouteBuilder
        public void Map(IEndpointRouteBuilder app)
        {
            app.MapPost("api/orders", async ([FromBody] Request request, [FromServices] IMediator mediator) =>
            {
                var result = await mediator.Send(new Command());
                return result.Value;
            });
        }
    }
}

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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 91 10/21/2024