Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/distantcam/endpointgenerator

Source Generator to help create minimal api endpoint mappings.
https://github.com/distantcam/endpointgenerator

csharp csharp-sourcegenerator dotnet roslyn source-generator

Last synced: 10 days ago
JSON representation

Source Generator to help create minimal api endpoint mappings.

Awesome Lists containing this project

README

        

# EndpointGenerator

[![Build Status](https://img.shields.io/github/actions/workflow/status/distantcam/EndpointGenerator/build.yml)](https://github.com/distantcam/EndpointGenerator/actions/workflows/build.yml)
[![NuGet Status](https://img.shields.io/nuget/v/EndpointGenerator.svg)](https://www.nuget.org/packages/EndpointGenerator/)
[![Nuget Downloads](https://img.shields.io/nuget/dt/EndpointGenerator.svg)](https://www.nuget.org/packages/EndpointGenerator/)

EndpointGenerator is a Roslyn Source Generator to add methods to call marked minimal api methods.

## Contents

* [NuGet packages](#nuget-packages)
* [Your code](#your-code)
* [What gets generated](#what-gets-generated)
* [How to use](#how-to-use)

## NuGet packages

https://nuget.org/packages/EndpointGenerator/

### Your code


```cs
public static class Basic
{
[EndpointGenerator.EndpointBuilder]
public static void Simple(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder builder) =>
builder.MapGet("/simple", () => TypedResults.Ok("Hello World"));

[EndpointGenerator.EndpointBuilder]
public static void Grouped(Microsoft.AspNetCore.Routing.RouteGroupBuilder builder) =>
builder.MapGet("/grouped", () => TypedResults.Ok("Hello World"));

[EndpointGenerator.EndpointGroupBuilder("prefix")]
public static void GroupedWithPrefix(Microsoft.AspNetCore.Routing.RouteGroupBuilder builder) =>
builder.MapGet("/grouped", () => TypedResults.Ok("Hello World"));
}
```
snippet source | anchor

### What gets generated


```cs
// The name will be "Map[AssemblyName]Endpoints"
public static IEndpointRouteBuilder MapEndpointGeneratorExampleEndpoints(this IEndpointRouteBuilder builder)
{
Basic.Simple(builder);
var group = builder.MapGroup("").WithName("Basic");
Basic.Grouped(group);
group = builder.MapGroup("prefix").WithName("Basic");
Basic.GroupedWithPrefix(group);
return builder;
}
```
snippet source | anchor

### How to use


```cs
var builder = WebApplication.CreateBuilder();
var app = builder.Build();

app.MapEndpointGeneratorExampleEndpoints();

app.Run();
```
snippet source | anchor