MinimalHelpers.Routing
1.0.6
See the version list below for details.
dotnet add package MinimalHelpers.Routing --version 1.0.6
NuGet\Install-Package MinimalHelpers.Routing -Version 1.0.6
<PackageReference Include="MinimalHelpers.Routing" Version="1.0.6" />
paket add MinimalHelpers.Routing --version 1.0.6
#r "nuget: MinimalHelpers.Routing, 1.0.6"
// Install MinimalHelpers.Routing as a Cake Addin #addin nuget:?package=MinimalHelpers.Routing&version=1.0.6 // Install MinimalHelpers.Routing as a Cake Tool #tool nuget:?package=MinimalHelpers.Routing&version=1.0.6
Minimal APIs Routing Helpers
A library that provides Routing helpers for Minimal APIs project.
Installation
The library is available on NuGet. Just search MinimalHelpers.Routing in the Package Manager GUI or run the following command in the Package Manager Console:
Install-Package MinimalHelpers.Routing
Usage
Automatic Route Endpoints registration
Create a class to hold your route handlers and make it implementing the IEndpointRouteHandler
interface:
public class PeopleHandler : MinimalHelpers.Routing.IEndpointRouteHandler
{
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGet("/api/people", GetList);
endpoints.MapGet("/api/people/{id:guid}", Get);
endpoints.MapPost("/api/people", Insert);
endpoints.MapPut("/api/people/{id:guid}", Update);
endpoints.MapDelete("/api/people/{id:guid}", Delete);
}
// ...
}
Call the MapEndpoints()
extension method on the WebApplication object inside Program.cs before the Run()
method invocation:
// using MinimalHelpers.Routing;
app.MapEndpoints();
app.Run();
By default, MapEndpoints()
will scan the calling Assembly to search for classes that implement the IEndpointRouteHandler
interface. If your route handlers are defined in another Assembly, you have two alternatives:
- Use the
MapEndpoints()
overload that takes the Assembly to scan as argument - Use the
MapEndpointsFromAssemblyContaining<T>()
extension method and specify a type that is contained in the Assembly you want to scan
You can also explicitly decide what types (among the ones that implement the IRouteEndpointHandler
interface) you want to actually map, passing a predicate to the MapEndpoints
method:
app.MapEndpoints(type =>
{
if (type.Name.StartsWith("Products"))
{
return false;
}
return true;
});
Contribute
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.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.