MinimalEndpoints.Abstractions
1.0.2
dotnet add package MinimalEndpoints.Abstractions --version 1.0.2
NuGet\Install-Package MinimalEndpoints.Abstractions -Version 1.0.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="MinimalEndpoints.Abstractions" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalEndpoints.Abstractions" Version="1.0.2" />
<PackageReference Include="MinimalEndpoints.Abstractions" />
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 MinimalEndpoints.Abstractions --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MinimalEndpoints.Abstractions, 1.0.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 MinimalEndpoints.Abstractions@1.0.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=MinimalEndpoints.Abstractions&version=1.0.2
#tool nuget:?package=MinimalEndpoints.Abstractions&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MinimalEndpoints
A compile-time source generator for ASP.NET Core that auto-registers Minimal API endpoints — zero reflection, zero boilerplate.
一个编译时 Source Generator,为 ASP.NET Core 自动注册 Minimal API 端点 —— 无反射、无样板代码。
✨ Features / 功能特性
| Feature | Description |
|---|---|
| Convention-based discovery | Any class inheriting ApiEndpointBase or implementing IApiEndpoint is auto-registered |
| Attribute-based control | Use [ApiEndpoint] to set lifetime, ordering, or skip endpoints |
| Assembly-level options | Customize generated class/namespace/method names via [ApiEndpointsOptions] |
| Zero reflection | Everything is resolved at compile time via Roslyn incremental source generator |
| Multiple overloads | Generated MapApiEndpoints supports both WebApplication and IEndpointRouteBuilder |
| DI lifecycle control | Singleton (default), Scoped, or Transient per-endpoint |
| 功能 | 说明 |
|---|---|
| 约定式发现 | 继承 ApiEndpointBase 或实现 IApiEndpoint 的类自动注册 |
| 特性配置 | 使用 [ApiEndpoint] 设置生命周期、排序、跳过 |
| 程序集级选项 | 通过 [ApiEndpointsOptions] 自定义生成的类名/命名空间/方法名 |
| 零反射 | 全部在编译时通过 Roslyn 增量 Source Generator 解析 |
| 多重载 | 生成的 MapApiEndpoints 同时支持 WebApplication 和 IEndpointRouteBuilder |
| DI 生命周期 | 支持 Singleton(默认)、Scoped、Transient 逐端点控制 |
📦 Installation / 安装
dotnet add package MinimalEndpoints.Abstractions
dotnet add package MinimalEndpoints.Generator
Or add to your .csproj / 或直接编辑 .csproj:
<ItemGroup>
<PackageReference Include="MinimalEndpoints.Abstractions" Version="*" />
<PackageReference Include="MinimalEndpoints.Generator" Version="*"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
🚀 Quick Start / 快速上手
1. Create an endpoint / 创建端点
using MinimalEndpoints.Abstractions;
using Microsoft.AspNetCore.Routing;
public class HelloEndpoint : ApiEndpointBase
{
public override void Register(IEndpointRouteBuilder routes)
{
routes.MapGet("/hello", () => new { Message = "Hello!" });
routes.MapGet("/hello/{name}", (string name) => new { Message = $"Hello, {name}!" });
}
}
2. Wire up in Program.cs / 在 Program.cs 中接线
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApiEndpoints(); // DI registration (auto-generated)
var app = builder.Build();
app.MapApiEndpoints(); // Route mapping (auto-generated)
app.Run();
That's it! All endpoints are discovered and registered at compile time.
就这样!所有端点在编译时自动发现并注册。
📖 Configuration / 配置
Per-endpoint / 端点级配置
[ApiEndpoint(
Lifetime = EndpointLifetime.Scoped, // DI lifecycle / DI 生命周期
Order = 10, // Registration order / 注册顺序
Skip = false // Skip auto-registration / 跳过自动注册
)]
public class MyEndpoint : ApiEndpointBase { ... }
Assembly-level / 程序集级配置
using MinimalEndpoints.Abstractions;
[assembly: ApiEndpointsOptions(
GeneratedNamespace = "MyApp", // Output namespace / 输出命名空间
GeneratedClassName = "EndpointExtensions", // Output class name / 输出类名
AddMethodName = "AddEndpoints", // DI method name / DI 方法名
MapMethodName = "MapEndpoints", // Route method name / 路由方法名
DefaultLifetime = EndpointLifetime.Scoped, // Default lifetime / 默认生命周期
EmitWebApplicationOverload = true, // Generate WebApplication overload
EmitEndpointRouteBuilderOverload = true // Generate IEndpointRouteBuilder overload
)]
Endpoint discovery / 端点发现机制
| Method | Description |
|---|---|
Inherit ApiEndpointBase |
Default convention / 默认约定 |
Implement IApiEndpoint |
Interface convention / 接口约定 |
[ApiEndpoint] attribute |
Explicit marking / 显式标记 |
Custom BaseType/InterfaceType |
Via [ApiEndpointsOptions] / 通过程序集选项自定义 |
📂 Project Structure / 项目结构
MinimalEndpoints/
├── src/
│ ├── MinimalEndpoints.Abstractions/ # Runtime types (net8.0)
│ └── MinimalEndpoints.Generator/ # Source Generator (netstandard2.0)
├── tests/
│ └── MinimalEndpoints.Tests/ # Generator unit tests
├── samples/
│ └── SampleWebApi/ # Usage example
└── .github/workflows/ci.yml # CI/CD pipeline
🔧 Packages / 包说明
| Package | Target | Description |
|---|---|---|
MinimalEndpoints.Abstractions |
net8.0 |
Runtime interfaces, attributes, base classes / 运行时接口、特性、基类 |
MinimalEndpoints.Generator |
netstandard2.0 |
Roslyn incremental source generator / Roslyn 增量源代码生成器 |
🏗️ CI/CD
- Build & Test — triggered on every push and PR to
main - Publish to NuGet — triggered when a version tag
v*is pushed (only if tests pass)
git tag v1.0.0 && git push origin v1.0.0
📄 License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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.