ChrisMavrommatis.MinimalEndpointDefinitions
2.0.1
dotnet add package ChrisMavrommatis.MinimalEndpointDefinitions --version 2.0.1
NuGet\Install-Package ChrisMavrommatis.MinimalEndpointDefinitions -Version 2.0.1
<PackageReference Include="ChrisMavrommatis.MinimalEndpointDefinitions" Version="2.0.1" />
paket add ChrisMavrommatis.MinimalEndpointDefinitions --version 2.0.1
#r "nuget: ChrisMavrommatis.MinimalEndpointDefinitions, 2.0.1"
// 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 | Versions 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. |
-
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.