![]() |
VOOZH | about |
dotnet add package BugFree.Controllers.Core --version 1.2.2026.616-beta1005
NuGet\Install-Package BugFree.Controllers.Core -Version 1.2.2026.616-beta1005
<PackageReference Include="BugFree.Controllers.Core" Version="1.2.2026.616-beta1005" />
<PackageVersion Include="BugFree.Controllers.Core" Version="1.2.2026.616-beta1005" />Directory.Packages.props
<PackageReference Include="BugFree.Controllers.Core" />Project file
paket add BugFree.Controllers.Core --version 1.2.2026.616-beta1005
#r "nuget: BugFree.Controllers.Core, 1.2.2026.616-beta1005"
#:package BugFree.Controllers.Core@1.2.2026.616-beta1005
#addin nuget:?package=BugFree.Controllers.Core&version=1.2.2026.616-beta1005&prereleaseInstall as a Cake Addin
#tool nuget:?package=BugFree.Controllers.Core&version=1.2.2026.616-beta1005&prereleaseInstall as a Cake Tool
BugFree 控制器核心框架,提供统一的 API 控制器基类体系、实体 CRUD 控制器、安全中间件、IP 访问控制、安全响应头注入等开箱即用的企业级 ASP.NET Core 基础设施。
BugFreeController — 继承 ControllerBase,内置 Success() / Fail() / Unauthorized() 快捷响应方法IResponseService 可替换策略,支持自定义响应构建行为BugFreeController
└── EmptyEntityController<TEntity> ← 实体工厂初始化
└── QueryEntityController<TEntity> ← 列表查询 (Query)
└── GetEntityController<TEntity> ← 单实体查询 (Get)
└── ReadOnlyEntityController<TEntity> ← 只读
└── EntityController<TEntity,TModel> ← 完整 CRUD
BugFree.XCode.Extensions + NewLife.XCode ORMAdd / Update / Upsert / Delete / Get / Query 标准操作ConfigController<TConfig> — 基于 BugFree.Configuration 的配置热更新控制器| 中间件 | 功能 |
|---|---|
| IpAccessControlMiddleware | IP 白名单/黑名单控制,支持单 IP、CIDR 网段、IP 范围、动态评估器 |
| SecurityHeaderMiddleware | 自动注入 CSP / HSTS / X-Frame-Options / Permissions-Policy 等安全响应头 |
Response + ResponseCode — 标准化的 API 响应结构(Success / Fail / 401 / 403 / 500 等)RunTimeContext — 运行时执行统计信息(SQL 次数、耗时、语句列表)AddCoreService() — 一键注册 CORS、缓存、响应压缩、API 版本控制AddBugFreeJsonOptions() — 统一 JSON 序列化选项(驼峰命名、忽略 null、默认转换器)GetClientIpAddress() — 支持反向代理的客户端 IP 提取(X-Forwarded-For / X-Real-IP 等)| 配置类 | 配置节点 | 说明 |
|---|---|---|
AccessDecisionRulesOptions |
AccessDecisionRules |
IP 访问控制规则 |
CorsOriginRulesOptions |
CorsOriginRules |
CORS 域名白名单 |
HeaderOptions |
Header |
安全响应头配置 |
HeaderSignatureOptions |
HeaderSignature |
请求头签名验证配置 |
PageOptions |
Page |
分页参数 |
RedisOptions |
Redis |
Redis 连接配置 |
Microsoft.AspNetCore.Authentication.JwtBearer + Asp.Versioning.Mvc.ApiExplorerdotnet add package BugFree.Controllers.Core
或通过 NuGet 包管理器搜索 BugFree.Controllers.Core。
在 Program.cs 中:
using BugFree.Controllers.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 添加控制器
builder.Services.AddControllers()
.AddBugFreeJsonOptions(); // 统一 JSON 序列化
// 添加 BugFree 核心服务(CORS、缓存、压缩、API 版本控制)
builder.Services.AddCoreService();
定义实体和模型(基于 XCode):
// 实体类
public class UserEntity : BugFreeEntity<UserEntity>, IEntity<UserDto>, new()
{
public String Name { get; set; }
public Int32 Age { get; set; }
}
// DTO 类
public class UserDto : IModel
{
public String Name { get; set; }
public Int32 Age { get; set; }
}
继承 EntityController 获得完整 CRUD:
[Area("System")]
public class UserController : EntityController<UserEntity, UserDto>
{
public UserController(IServiceProvider serviceProvider) : base(serviceProvider) { }
// 已自动包含:Add / Update / Upsert / Delete / Get / Query
}
[Area("System")]
public class UserController : ReadOnlyEntityController<UserEntity>
{
public UserController(IServiceProvider serviceProvider) : base(serviceProvider) { }
// 已自动包含:Get / Query
}
[Area("System")]
public class AppConfigController : ConfigController<AppConfigOptions>
{
public AppConfigController(IServiceProvider serviceProvider) : base(serviceProvider) { }
// 已自动包含:Get / Save
}
在配置文件(如 appsettings.json)中:
{
"AccessDecisionRules": {
"Allows": {
"Enabled": true,
"IpRules": ["192.168.1.0/24", "10.0.0.1-10.0.0.100", "114.114.114.114"]
},
"Denies": {
"Enabled": true,
"IpRules": ["0.0.0.0/8", "10.0.0.5"]
}
}
}
192.168.1.0/24)、IP 范围(10.0.0.1-10.0.0.100)DynamicEvaluator 动态扩展{
"CorsOriginRules": {
"Enabled": true,
"AllowedDomains": ["example.com", "*.example.com"]
}
}
{
"Header": {
"Enabled": true,
"RemoveHeaders": ["X-AspNet-Version", "X-AspNetMvc-Version"],
"XFrameOptions": "SAMEORIGIN",
"StrictTransportSecurity": "max-age=31536000; includeSubDomains",
"ContentSecurityPolicy": "default-src 'self'; script-src 'self'"
}
}
提示:开发环境默认不启用安全响应头,生产环境自动启用。
所有 API 返回统一格式的 Response 结构:
{
"code": 200,
"message": "执行成功",
"data": { ... },
"runtime": null
}
| 响应码 | 说明 |
|---|---|
| 200 | 成功 |
| 201 | 新建或修改成功 |
| 400 | 请求失败 |
| 401 | 未授权 |
| 403 | 禁止访问 |
| 404 | 资源不存在 |
| 500 | 服务器异常 |
| 包名 | 说明 |
|---|---|
BugFree.Cache |
多级缓存(HybridCache) |
BugFree.XCode.Extensions |
XCode ORM 扩展 |
BugFree.Serialization |
JSON 序列化 |
Microsoft.AspNetCore.Authentication.JwtBearer |
JWT 认证 |
Asp.Versioning.Mvc.ApiExplorer |
API 版本控制 |
BugFree.Controllers.Core/
├── Abstractions/ ← 接口定义(IResponseService)
├── Attributes/ ← 特性(SignatureAttribute)
├── Core/
│ ├── Application/ ← 默认响应服务实现
│ ├── Basis/ ← 控制器基类体系
│ ├── Contexts/ ← 属性上下文
│ └── Middleware/ ← 中间件
├── Extensions/ ← 扩展方法(DI 注册、HttpContext)
├── Models/
│ ├── Requests/ ← 请求模型(Page)
│ └── Responses/ ← 响应模型(Response, RunTimeContext)
└── Options/ ← 配置选项
本项目基于 MIT 许可证开源。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.2026.616-beta1005 | 43 | 6/16/2026 |
| 1.2.2026.615-beta1108 | 49 | 6/15/2026 |
| 1.2.2026.614-beta1951 | 45 | 6/14/2026 |
| 1.2.2026.613-beta1704 | 53 | 6/13/2026 |
| 1.1.2026.612-beta1017 | 44 | 6/12/2026 |
| 1.1.2026.128-beta1507 | 75 | 1/28/2026 |
| 1.1.2026.121-beta1615 | 73 | 1/21/2026 |
| 1.1.2026.121-beta1424 | 68 | 1/21/2026 |
| 1.1.2026.121-beta1413 | 64 | 1/21/2026 |
| 1.1.2026.121-beta1401 | 62 | 1/21/2026 |
| 1.1.2026.121-beta1136 | 66 | 1/21/2026 |
统一 API/MVC 控制器基类体系;5层实体控制器(Empty→Query→Get→ReadOnly→Entity);IP 访问控制中间件;安全响应头注入;统一响应模型;配置热更新控制器。