NetKernel.DotNetForge
1.0.0.5
dotnet add package NetKernel.DotNetForge --version 1.0.0.5
NuGet\Install-Package NetKernel.DotNetForge -Version 1.0.0.5
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="NetKernel.DotNetForge" Version="1.0.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetKernel.DotNetForge" Version="1.0.0.5" />
<PackageReference Include="NetKernel.DotNetForge" />
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 NetKernel.DotNetForge --version 1.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetKernel.DotNetForge, 1.0.0.5"
#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 NetKernel.DotNetForge@1.0.0.5
#: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=NetKernel.DotNetForge&version=1.0.0.5
#tool nuget:?package=NetKernel.DotNetForge&version=1.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotNetForge
企业级 .NET 8.0 基础设施类库,旨在为中大型应用提供开箱即用的基础能力封装与参考实现。本 README 为详细版,包含模块说明、安装与使用示例、目录结构与依赖说明。
目录
- 项目概述
- 详细模块说明
- 快速开始(安装与常用示例)
- 项目结构
- 配置说明
- 依赖项
- 贡献指南与许可证
项目概述
DotNetForge 提供常用企业级组件的实现与封装,覆盖:
- 身份与认证(JWT、Refresh Token)
- 云厂商集成(腾讯云、阿里云常用服务)
- 数据访问(Dapper 扩展、EF 支持、事务封装)
- 文件处理(Excel/Word 操作、压缩、图片处理)
- 日志与监控(Serilog 集成、日志中间件)
- 任务调度(Hangfire/Quartz 示例)
- 安全工具(对称/非对称加密、哈希、密码策略)
- 其它工具(Http 客户端封装、API 返回格式、异常处理、守卫类)
目标是减少样板代码、统一工程实践、提升开发效率并提供可定制的实现。
详细模块说明
基础设施(Infrastructure)
- Entity: 实体基类(EntityBase、AuditEntity、FullAuditEntity),包含主键、审计字段等通用属性。
- Dto: DTO 基类(DtoBase、ValueDto<T>)用于接口层的数据传输规范化。
- Exceptions: 自定义异常类型(BadRequestException、NotFoundException、GatewayException),方便统一异常处理与错误码映射。
- Security: 常见加密工具(AES、RSA、MD5、SHA、HMAC、PasswordHasher),封装常用加解密与签名操作。
- Utils: 常用工具类(Json 辅助、图片处理、Guard 参数校验、DelegateExecutionChecker 等)。
- Impl.QRCode: 基于 SkiaSharp 的二维码生成实现。
Web(Web)
- Api: 统一 API 返回格式 ApiResult<T>,包含状态码与消息约定。
- Jwt: JWT 生成与验证(JwtProvider、IAuthenticator、RefreshTokenStore),支持自定义 Claim 与过期策略。
- Attributes: MVC 特性(ApiResultFilter、Authentication、ModelValidation)用于控制器层的统一行为。
- Authorization: 授权策略实现示例。
- ApiLog: API 请求/响应日志记录中间件与实现。
- Http: HttpClient 封装与重试策略、超时设置等。
数据库(Databse)
- Db: 数据库连接与事务封装,支持同步/异步操作。
- Dp: Dapper 扩展(通用 CRUD、批量操作、分页扩展)。
- EF: EntityFramework Core 辅助配置与通用仓储示例。
- Infrastructure: 数据库方言与配置抽象,便于同时支持 MySQL/SQLServer/Oracle 等。
文件处理(File)
- Compress: Zip/GZip 压缩与解压工具。
- NPOI: Excel/Word 读写工具封装示例。
- Aspose/Spire: 提供基于第三方商业库的文档处理示例(若包含商业库,请结合授权使用)。
- HtmlToOpenXml: HTML 转 Word 的工具方法。
云服务集成
- 腾讯(Tencent): Cos(对象存储)、Sms(短信)、Captcha(验证码)、WeXin(微信消息/认证)、WxPay(微信支付)、TokenHub(Token 管理)等。
- 阿里(Alibaba): Ocr(识别)、AddressPurification(地址解析)等示例。
第三方 API 集成
- QiChaCha、TianYanCha 等企业信息查询示例。
消息队列 & 调度
- Mq: RabbitMQ 集成示例,支持发布/订阅模式。
- TaskSchedule: Hangfire 与 Quartz 的集成示例与使用说明。
反爬虫与防护
- AntiScraping: IP 限流、客户端限流、代理头处理等中间件示例。
日志系统
- Serilog 结构化日志、LogDashboard 集成与请求日志中间件。
快速开始(详细示例)
- 安装(本地项目直接引用或通过 NuGet)
dotnet add package NetKernel.DotNetForge
- 在 ASP.NET Core Web 项目中使用(Program.cs)
using DotNetForge.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 加载 JSON 配置(示例扩展方法)
builder.Configuration.AddJsonSetting("appsettings.json");
// JWT 认证示例
builder.Services.AddJwtAuthentication<Authenticator>(options =>
{
options.Secret = builder.Configuration["Jwt:Secret"] ?? "your-secret-key";
options.ExpireMinutes = int.Parse(builder.Configuration["Jwt:ExpireMinutes"] ?? "30");
});
// 注册 Web API 约定(控制器、模型验证、全局过滤器等)
builder.Services.AddWebApi();
// 腾讯云 COS
builder.Services.AddTencentCos(builder.Configuration);
// Hangfire
builder.Services.AddHangfire(builder.Configuration);
// Serilog
builder.Services.AddSerilog(builder.Configuration);
var app = builder.Build();
app.UseApiResultMiddleware(); // 示例:统一响应中间件
app.Run();
- 数据库与事务(示例)
using var db = new Db("YourConnectionString");
// 查询示例
var users = await db.QueryAsync<User>("SELECT * FROM Users WHERE IsActive = 1");
// 事务示例
using var tx = db.BeginTransaction();
try
{
await db.ExecuteAsync("UPDATE Accounts SET Balance = Balance - @Amount WHERE Id = @Id", new { Amount = 100, Id = 1 });
await db.ExecuteAsync("UPDATE Accounts SET Balance = Balance + @Amount WHERE Id = @Id", new { Amount = 100, Id = 2 });
tx.Commit();
}
catch
{
tx.Rollback();
throw;
}
- JWT 使用示例
var provider = app.Services.GetRequiredService<JwtProvider>();
var token = await provider.GenerateTokenAsync(userId, claims);
[Authentication]
public class SecureController : ControllerBase { }
- 云存储上传示例
public class MyCosService : BaseCosService
{
public override string Bucket => "my-bucket";
}
var service = new MyCosService();
await service.PutObjectAsync("file.txt", "local/path.txt");
配置说明
- 建议使用 appsettings.json + 环境变量组合管理配置。
- 核心配置项示例:
{
"Jwt": { "Secret": "...", "ExpireMinutes": 30 },
"ConnectionStrings": { "Default": "..." },
"Tencent": { /* cos/sms 等配置 */ }
}
具体模块可能需要额外配置项,请参阅模块内的 README 或代码注释。
项目结构
DotNetForge/
├── Alibaba/ # 阿里云服务
├── AntiScraping/ # 反爬虫防护
├── Databse/ # 数据库操作
├── File/ # 文件处理
├── Infrastructure/ # 核心基础设施
├── Logger/ # 日志系统
├── Middleware/ # 中间件
├── Mq/ # 消息队列
├── QiChaCha/ # 企查查 API
├── TaskSchedule/ # 任务调度
├── Tencent/ # 腾讯云服务
├── TianYanCha/ # 天眼查 API
├── Weather/ # 天气服务
└── Web/ # Web 开发支持
依赖项(示例)
- ORM: EntityFramework Core, Dapper
- 文档: Aspose.Words, NPOI, Spire.Doc
- 云服务: TencentCloudSDK, AlibabaCloud SDK
- 消息队列: RabbitMQ.Client
- 调度: Hangfire, Quartz
- 日志: Serilog, LogDashboard
- 安全: Microsoft.AspNetCore.Authentication.JwtBearer
- 其他: AutoMapper, Newtonsoft.Json, SkiaSharp
注:部分依赖为商业库(如 Aspose),请根据授权情况选择使用或替换开源替代品。
测试与 CI
- 建议在仓库中添加单元测试项目(xUnit / NUnit)并在 CI 中运行。
- 可配置 GitHub Actions / Azure Pipelines 对构建、测试、静态分析进行自动化处理。
贡献指南
- 欢迎提交 Issue 与 Pull Request。
- 请在提交代码前运行格式化和单元测试,并尽量保持代码兼容 .NET 8。
- 若添加第三方商用库,请在 PR 描述中注明授权要求。
许可证
本项目采用 MIT 许可证,详见 LICENSE 文件。
版权所有 © 2024 DotNetForge 团队
| 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
- AlibabaCloud.SDK.Dysmsapi20170525 (>= 4.4.0)
- AlibabaCloud.SDK.Ocr-api20210707 (>= 3.1.1)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- AspNetCoreRateLimit (>= 5.0.0)
- Aspose.Words (>= 24.12.0)
- AWSSDK.S3 (>= 4.0.23.4)
- AWSSDK.S3Control (>= 4.0.11.6)
- COSXML.Wpre (>= 1.0.7)
- Dapper (>= 2.1.35)
- Dapper.SimpleCRUD (>= 2.3.0)
- DocumentFormat.OpenXml (>= 3.2.0)
- Hangfire (>= 1.8.14)
- Hangfire.MemoryStorage (>= 1.8.1.1)
- HtmlToOpenXml.dll (>= 3.2.2)
- LogDashboard (>= 1.4.8)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.10)
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.10)
- MySql.Data (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
- NPOI (>= 2.7.1)
- Oracle.ManagedDataAccess.Core (>= 23.6.0)
- PdfSharpCore (>= 1.3.65)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.2)
- RabbitMQ.Client (>= 6.8.1)
- Serilog (>= 4.0.2)
- Serilog.Extensions.Hosting (>= 8.0.0)
- Serilog.Settings.Configuration (>= 8.0.4)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
- Serilog.Sinks.MySQL (>= 5.0.0)
- SharpCompress (>= 0.48.1)
- SkiaSharp (>= 3.119.0)
- SkiaSharp.QrCode (>= 0.7.0)
- Spire.Doc (>= 12.11.7)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.8.1)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.8.1)
- TencentCloudSDK (>= 3.0.1106)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.