Svrooij.EndpointMapper 0.3.2

dotnet add package Svrooij.EndpointMapper --version 0.3.2
                    
NuGet\Install-Package Svrooij.EndpointMapper -Version 0.3.2
                    
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="Svrooij.EndpointMapper" Version="0.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Svrooij.EndpointMapper" Version="0.3.2" />
                    
Directory.Packages.props
<PackageReference Include="Svrooij.EndpointMapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Svrooij.EndpointMapper --version 0.3.2
                    
#r "nuget: Svrooij.EndpointMapper, 0.3.2"
                    
#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.
#:package Svrooij.EndpointMapper@0.3.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Svrooij.EndpointMapper&version=0.3.2
                    
Install as a Cake Addin
#tool nuget:?package=Svrooij.EndpointMapper&version=0.3.2
                    
Install as a Cake Tool

πŸš€ Svrooij.EndpointMapper

Stop writing boilerplate. Start building APIs. ⚑

A powerful .NET source generator that eliminates repetitive code when building ASP.NET Core minimal APIs. Write less, ship more, and enjoy not having to write boilerplate code.

Currently this project is an experimental prototype. Features might be added or changed in future releases.

Why You'll Love It

✨ Zero Runtime Overhead – All magic happens at compile time, not runtime
🎯 Type-Safe – Full IntelliSense support with generated code
πŸ“¦ Less Boilerplate – Auto-discover and register endpoints effortlessly
πŸ” Smart DTO Mapping – Only select what you need from your database
βœ… FluentValidation Integration – Validation filters generated automatically
πŸ› οΈ Easy to Use – Minimal setup, maximum productivity

Get Started in Seconds

Install the NuGet package:

dotnet add package Svrooij.EndpointMapper

Done! No configuration needed. The source generator does the rest. ✨

<details> <summary>Or add it manually to your project file</summary>

<ItemGroup>
  <PackageReference Include="Svrooij.EndpointMapper" Version="1.0.0" 
                    OutputItemType="Analyzer" 
                    ReferenceOutputAssembly="false" />
</ItemGroup>

</details>

Features

Being a source generator, this library eliminates boilerplate by generating code at compile time. No reflection, no runtime discoveryβ€”just blazing-fast, type-safe endpoint management.

🎯 Easy Endpoint Mapping

Never write repetitive endpoint registration again. Simply implement IMapEndpoint and watch it get automatically discovered and registered.

public class WeatherEndpoint : IMapEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("/weather", () => "Sunny")
           .WithName("GetWeather")
           .WithOpenApi();
           
        app.MapPost("/weather", (WeatherRequest request) => 
            Results.Ok($"Weather updated to {request.Description}"))
           .WithName("UpdateWeather")
           .WithOpenApi();
    }
}

// In Program.cs - that's it!
app.MapEndpointFromMyApi(); // ✨ Auto-generated extension method

What you get:

  • πŸ” Automatic discovery of all IMapEndpoint implementations
  • 🏎️ Compile-time code generation (zero runtime cost)
  • πŸ“ Organized, maintainable code structure
  • πŸ“¦ Project-specific extension methods

πŸ’‘ Selective DTO Mapping

Stop fetching entire database records just to return a few fields. Generate optimized property selectors at compile timeβ€”no reflection, no LINQ expressions. Original idea.

// Your domain model
public class User
{
    public int Id { get; set; }
    public required string Name { get; set; }
    public required string Email { get; set; }
    public string? Address { get; set; }
}

// Your DTO with automatic mapping generation
[Svrooij.EndpointMapper.GenerateSelect(typeof(User))]
public class UserDto
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? Email { get; set; }
    public string? Address { get; set; }
}

The magic:

  • ✨ Generates two extension methods automatically
  • πŸ“Š SelectUserDto(IQueryable<User>, properties) – for Entity Framework queries
  • πŸ”„ SelectUserDto(User, properties) – for object mapping
  • πŸš€ Pure, optimized code generation (no reflection at runtime)
  • 🏍️ Select null for not selected columns, before querying the database.

Real-world example:

// Database query
var userDtos = await dbContext.Users
    .SelectUserDto("Id,Name")  // 🎯 Only fetch these columns!
    .ToListAsync();

Perfect for APIs where clients can request specific fields!

This feature shines when you have large entities with many properties but your API consumers only need a few. Save bandwidth, reduce N+1 queries, and let the compiler do the heavy lifting.

βœ… FluentValidation Endpoint Filter

Validation code tends to be verbose and repetitive. Not anymore. Automatically generate endpoint filters for all your AbstractValidator<T> implementations.

public class FluentValidationEndpoint : Svrooij.EndpointMapper.IMapEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPost("/users", PostNewUserAsync)
           .WithOpenApi()
           .WithTags("Users")
           .AddValidationWithUserDtoValidator(); // ✨ Auto-generated!
    }

    private static async Task<IResult> PostNewUserAsync(UserDto userDto) 
        => Results.Ok($"User {userDto.Name} created!");
}

// Your validator
public class UserDtoValidator : AbstractValidator<UserDto>
{
    public UserDtoValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty().WithMessage("Name is required")
            .MinimumLength(2).WithMessage("At least 2 characters");
    }
}

What's generated:

  • πŸ›‘οΈ UserDtoValidatorFilter : IEndpointFilter
  • πŸ”§ AddValidationWithUserDtoValidator() extension method

See the complete example for more details.

Examples & Samples

Want to see it in action? Check out the complete sample project with:

  • πŸ“ Multiple endpoint examples
  • πŸ” Selective DTO mapping usage
  • βœ… FluentValidation integration
  • πŸ§ͺ Full test suite

Roadmap & Contributing

This is an active open-source project! Have ideas? Found a bug? Contributions are welcome!

Feel free to:

License

MIT License – see the LICENSE file for details.

Source Generators inspiration


Happy building! πŸŽ‰

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.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
0.3.2 217 12/19/2025
0.3.1 200 11/28/2025
0.3.0 170 11/7/2025
0.2.2 207 11/5/2025
0.2.1 142 11/1/2025
0.1.0 207 10/27/2025