Saturna.DorApiExplorer
1.1.1
dotnet add package Saturna.DorApiExplorer --version 1.1.1
NuGet\Install-Package Saturna.DorApiExplorer -Version 1.1.1
<PackageReference Include="Saturna.DorApiExplorer" Version="1.1.1" />
<PackageVersion Include="Saturna.DorApiExplorer" Version="1.1.1" />
<PackageReference Include="Saturna.DorApiExplorer" />
paket add Saturna.DorApiExplorer --version 1.1.1
#r "nuget: Saturna.DorApiExplorer, 1.1.1"
#:package Saturna.DorApiExplorer@1.1.1
#addin nuget:?package=Saturna.DorApiExplorer&version=1.1.1
#tool nuget:?package=Saturna.DorApiExplorer&version=1.1.1
<p align="center"> <img src="icon.png" alt="DorApiExplorer" width="160" /> <h1 align="center">DorApiExplorer</h1> </p>
<p align="center"> Automate API endpoints registration.<br> <b>DorApiExplorer</b> provides a source-generated endpoints registration for minimal API in ASP NET Core. </p>
Features
- NET 6 / 8 / 10 support
- Automatic endpoints registration
Getting Started
Install the package via NuGet :
dotnet add package Saturna.DorApiExplorer
Or using the Package Manager :
Install-Package Saturna.DorApiExplorer
Usage
DorApiExplorer allows you to automatically register your endpoints while splitting them in separated files.
Start by adding the generated extension method to your DI container and the mapping extension method to your app :
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services
.AddDorApiExplorer(); // <-- here
var app = builder.Build();
app.MapEndpoints(); // <-- here
Create your endpoint, here for the exemple we will keep it as light as possible :
using DorApiExplorer;
public sealed class WeatherForecastEndpoint
: IEndpoint
{
private static readonly ReadOnlyMemory<string> Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public void MapEndpoint(IEndpointRouteBuilder app)
{
app.MapGet("/weatherforecast/{amount:int}", (int amount)
{
foreach (var element in Enumerable.Range(1, amount).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
Summaries.Span[Random.Shared.Next(Summaries.Length)]
)))
{
return element;
}
}).WithName("GetWeatherForecast");
}
}
It also offers a way to create MapGroup, to achieve this you can use the EndpointPrefixAttribute on your class or on a parent one.
using DorApiExplorer;
[EndpointPrefix("/api")]
public abstract class ApiEndpoints : IEndpoint
{
public abstract void MapEndpoint(IEndpointRouteBuilder app);
}
[EndpointPrefix("/weatherforecast")]
public sealed class WeatherForecastEndpoint
: ApiEndpoints
{
public override void MapEndpoint(IEndpointRouteBuilder app)
{
app.MapGet("/{amount:int}", async (IMediator mediator, int amount) => await mediator.Send(new WeatherForecastQuery(amount)))
.WithName("GetWeatherForecast");
}
}
This will create a route like this : /api/weatherforecast/{amount:int}.
NB : This attribute is optional.
And that's it !
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 | 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 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
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.