ChrisMavrommatis.MinimalEndpointDefinitions 2.0.1

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

// Install ChrisMavrommatis.MinimalEndpointDefinitions as a Cake Tool
#tool nuget:?package=ChrisMavrommatis.MinimalEndpointDefinitions&version=2.0.1                

MinimalEndpointDefinitions

ChrisMavrommatis.MinimalEndpointDefinitions is a .NET Package aimed to provide the Endpoint pattern in your projects by using Definitions and Minimal Endpoints behind the scenes.

The project aims to provide with utilities that will make your API structure look like this

Endpoints
 - Users
    - Get.cs
    - List.cs
    - Create.cs
    - Delete.cs
  - UsersGroup.cs
  - Products
    - Get.cs
    - List.cs
    - Create.cs
    - Delete.cs
  - ProductsGroup.cs

Installation

Install the package via NuGet Package Manager

Install-Package ChrisMavrommatis.MinimalEndpointDefinitions

Or via .NET CLI:

dotnet add package ChrisMavrommatis.MinimalEndpointDefinitions

Usage

In your startup class use the AddMinimalEndpointDefinitions<T> extension method while registering your services. This will discover all of the definitions in the assembly of T

builder.Services.AddMinimalEndpointDefinitions<IModuleMarker>();

Then use the UseMinimalEndpointDefinitions extension method

app.UseMinimalEndpointDefinitions();

Now you are ready to create endpoints

Creating Endpoints

The library provides a IEndpointDefinition interface that you can use to define an endpoint. You can then use the DefineEndpoint method to register the endpoint.

namespace MyProject.Endpoints.Users;

public class List : IEndpointDefinition
{
  
  public void DefineEndpoint(IEndpointRouteBuilder endpoints)
  {
    endpoints.MapGet("/api/users", HandleAsync);
  }

  internal async Task<IResult> HandleAsync(CancellationToken cancellationToken = default)
  {
    // Your logic here
  }
}

It also provides a IEndpointGroupDefinition interface that you can use to define an endpoint group. Here is an example of how the UsersGroup file would look like:

namespace MyProject.Endpoints;

internal class UsersGroup : IEndpointGroupDefinition
{
  public RouteGroupBuilder DefineEndpointGroup(IEndpointRouteBuilder endpoints)
  {
    return endpoints.MapGroup("/api/users")
        .WithTags("Users")
        .WithGroupName("Users");
  }
}

And this is how List would look like if it was part of a group

namespace MyProject.Endpoints.Users;
public class List : IEndpointDefinition<UsersGroup>
{
  public void DefineEndpoint(RouteGroupBuilder group)
  {
    endpoints.MapGet("/", HandleAsync);
  }

  internal async Task<IResult> HandleAsync(CancellationToken cancellationToken = default)
  {
    // Your logic here
  }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

    • No dependencies.
  • net9.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
2.0.1 3 11/25/2024
2.0.0 78 11/13/2024
1.0.0 241 7/24/2024