YLFramework.AspNetCore
2.0.0-alpha.1
This is a prerelease version of YLFramework.AspNetCore.
dotnet add package YLFramework.AspNetCore --version 2.0.0-alpha.1
NuGet\Install-Package YLFramework.AspNetCore -Version 2.0.0-alpha.1
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="YLFramework.AspNetCore" Version="2.0.0-alpha.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YLFramework.AspNetCore" Version="2.0.0-alpha.1" />
<PackageReference Include="YLFramework.AspNetCore" />
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 YLFramework.AspNetCore --version 2.0.0-alpha.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: YLFramework.AspNetCore, 2.0.0-alpha.1"
#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 YLFramework.AspNetCore@2.0.0-alpha.1
#: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=YLFramework.AspNetCore&version=2.0.0-alpha.1&prerelease
#tool nuget:?package=YLFramework.AspNetCore&version=2.0.0-alpha.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
YLFramework.AspNetCore
YLFramework.AspNetCore 为 ASP.NET Core 应用提供一组跨场景的基础设施:统一的 API 响应模型、连接管道扩展、异常处理中间件、模块化路由注册。命名空间保留 Framework 前缀,即 Framework.AspNetCore(以及 Application / Mvc / Routing / Microsoft.AspNetCore.Connections 等子命名空间)。
功能概览
| 命名空间 | 关键类型 | 作用 |
|---|---|---|
Framework.AspNetCore |
IKestrelMiddleware |
Kestrel 中间件标记接口与基础约定 |
Framework.AspNetCore.Application |
ApplicationContext / ApplicationBuilder / ApplicationDelegate / IApplicationMiddleware |
自定义"应用中间件"管道,独立于 ASP.NET Core 自身的 RequestDelegate 链,可承载横切逻辑 |
Framework.AspNetCore.Middlewares |
ApiExceptionMiddleware |
捕获下游异常,统一转换为 IApiResponse 响应并写入 ILogger |
Framework.AspNetCore.Mvc |
ApiResponse<T> / ApiResult / IApiResponse / ApiException |
统一前后端交互格式,封装 success / code / message / data / exception 字段 |
Framework.AspNetCore.Routing |
IBaseRouter / RouterExtensions |
通过反射扫描实现 IBaseRouter 的模块类并自动注册 MVC 路由,配合"模块化 API"模式 |
Framework.AspNetCore.Microsoft.AspNetCore.Connections |
ConnectionBuilderExtensions / ConnectionFactoryTypeUtil / ServiceCollectionExtensions |
扩展 ConnectionBuilder 以便在 Kestrel 连接级管道注册自定义中间件工厂 |
Framework.AspNetCore.System.Net |
HttpContextExtensions / HttpRequestExtensions |
常用 HttpContext / HttpRequest 工具方法(如 IsMobileBrowser) |
快速上手
var builder = WebApplication.CreateBuilder(args);
// 1) 注册统一 API 响应 + 模块化路由扫描
builder.Services.AddControllers();
builder.Services.AddFrameworkAspNetCore(builder.Configuration);
// 2) 构建应用
var app = builder.Build();
// 3) 使用统一异常中间件
app.UseApiExceptionHandler();
// 4) 注册业务模块(实现 IBaseRouter 的类自动被发现)
app.UseFrameworkRouters();
模块化路由
实现 IBaseRouter:
public class UserRouter : IBaseRouter
{
public void AddModuleRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapGet("/api/users", () => Results.Ok(new { id = 1, name = "alice" }));
}
}
调用 AddIoC<TAssembly>() 把目标程序集加入模块列表后,AddRouters 会逐个实例化模块并注册其路由。
统一响应
控制器与服务可直接返回 ApiResult.Ok(data) / ApiResult.Fail(code, msg),中间件会负责序列化与异常兜底。
版本
2.0.0-alpha.1,版本由本项目 csproj 的 <Version> 独立声明。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- BouncyCastle.Cryptography (>= 2.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on YLFramework.AspNetCore:
| Package | Downloads |
|---|---|
|
YLFramework.AspNetCore.Middleware
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-alpha.1 | 37 | 10/17/2026 |
| 1.0.3-alpha.6 | 78 | 5/1/2026 |
| 1.0.3-alpha.5 | 73 | 5/1/2026 |
| 1.0.3-alpha.4 | 79 | 4/12/2026 |
| 1.0.3-alpha.3 | 78 | 4/12/2026 |
| 1.0.3-alpha.2 | 77 | 4/12/2026 |
| 1.0.3-alpha.1 | 76 | 4/11/2026 |
| 1.0.2-alpha.7 | 85 | 4/11/2026 |
| 0.0.1 | 167 | 12/31/2025 |
| 0.0.1-alpha.1 | 74 | 4/11/2026 |