Shimakaze.MinimalApi.Plus.SourceGenerator 0.1.7

dotnet add package Shimakaze.MinimalApi.Plus.SourceGenerator --version 0.1.7
                    
NuGet\Install-Package Shimakaze.MinimalApi.Plus.SourceGenerator -Version 0.1.7
                    
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="Shimakaze.MinimalApi.Plus.SourceGenerator" Version="0.1.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shimakaze.MinimalApi.Plus.SourceGenerator" Version="0.1.7" />
                    
Directory.Packages.props
<PackageReference Include="Shimakaze.MinimalApi.Plus.SourceGenerator" />
                    
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 Shimakaze.MinimalApi.Plus.SourceGenerator --version 0.1.7
                    
#r "nuget: Shimakaze.MinimalApi.Plus.SourceGenerator, 0.1.7"
                    
#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 Shimakaze.MinimalApi.Plus.SourceGenerator@0.1.7
                    
#: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=Shimakaze.MinimalApi.Plus.SourceGenerator&version=0.1.7
                    
Install as a Cake Addin
#tool nuget:?package=Shimakaze.MinimalApi.Plus.SourceGenerator&version=0.1.7
                    
Install as a Cake Tool

Shimakaze.MinimalApi.Plus

一个用于简化 .NET Minimal API 开发的工具库,通过 Source Generator 提供更优雅的 API 端点定义方式。

Shimakaze.MinimalApi.Plus
Shimakaze.MinimalApi.Plus.SourceGenerator

特性

  • 基于 Source Generator 的编译时代码生成
  • 支持依赖注入
  • 类型安全的路由定义
  • 简洁的 API 端点组织方式
  • AOT 兼容(.NET 9.0 及以上版本)

快速开始

1. 安装

dotnet add package Shimakaze.MinimalApi.Plus
dotnet add package Shimakaze.MinimalApi.Plus.SourceGenerator

2. 创建 API 端点

[ApiEndpoints]
public sealed class SimpleApiEndpoints(SimpleServices services) : ApiEndpoints
{
    [HttpGet("/weatherforecast")]
    public WeatherForecast[] GetWeatherForecasts()
        => services.GetWeatherForecasts();
}

3. 注册服务

var builder = WebApplication.CreateBuilder(args);

// 添加服务
builder.Services.AddTransient<SimpleServices>();
// 添加端点
builder.Services.AddEndpoints();

var app = builder.Build();

// 映射端点
app.MapEndpoints();

app.Run();

核心概念

ApiEndpoints 基类

提供对 HttpContext 的便捷访问:

public abstract class ApiEndpoints
{
    protected HttpContext Context { get; set; }
    protected HttpRequest Request => Context.Request;
    protected HttpResponse Response => Context.Response;
    // ... 其他便捷属性
}

ApiEndpointsAttribute

标记类为 API 端点集合:

[AttributeUsage(AttributeTargets.Class)]
public sealed class ApiEndpointsAttribute : Attribute
{
}

AOT 兼容性

  • .NET 9.0 及以上版本:完全支持 AOT
  • .NET 8.0 及更早版本:不支持 AOT,因为依赖 TypeDescriptor 的类型转换

限制

  • 不支持泛型类型
  • 不支持抽象类型
  • .NET 8.0 及更早版本不支持 AOT

许可证

MIT License

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.1.7 110 2/27/2026
0.1.6 106 2/27/2026
0.1.5 112 2/27/2026
0.1.4 106 2/26/2026
0.1.3 115 2/26/2026
0.1.2 132 1/1/2026
0.1.1 113 12/28/2025
0.1.0 112 12/27/2025