NetKernel.DotNetForge 1.0.0.1

dotnet add package NetKernel.DotNetForge --version 1.0.0.1
                    
NuGet\Install-Package NetKernel.DotNetForge -Version 1.0.0.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="NetKernel.DotNetForge" Version="1.0.0.1" />
                    
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.1" />
                    
Directory.Packages.props
<PackageReference Include="NetKernel.DotNetForge" />
                    
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 NetKernel.DotNetForge --version 1.0.0.1
                    
#r "nuget: NetKernel.DotNetForge, 1.0.0.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 NetKernel.DotNetForge@1.0.0.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=NetKernel.DotNetForge&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=NetKernel.DotNetForge&version=1.0.0.1
                    
Install as a Cake Tool

DotNetForge

企业级 .NET 8.0 基础设施类库

项目概述

DotNetForge 是一个功能丰富的 .NET 企业级基础设施类库,集成了多种云服务、数据库操作、安全加密、Web API 开发等功能,旨在为 .NET 开发者提供开箱即用的组件支持。

  • 框架版本: .NET 8.0
  • 项目类型: 类库 (Class Library)
  • NuGet 包依赖: 40+

核心模块

1. 基础设施 (Infrastructure)

模块 说明
Entity 实体基类 (EntityBase, AuditEntity, FullAuditEntity)
Dto DTO 基类 (DtoBase, ValueDto<T>)
Exceptions 自定义异常 (BadRequestException, NotFoundException, GatewayException)
Security 安全加密 (AES, RSA, MD5, SHA, HMAC, PasswordHasher)
Utils 工具类 (JSON, Image, Guard, DelegateExecutionChecker)
Impl.QRCode 二维码生成 (基于 SkiaSharp)

2. Web 开发 (Web)

模块 说明
Api 统一 API 返回格式 (ApiResult<T>)
Jwt JWT 认证 (JwtProvider, IAuthenticator, RefreshTokenStore)
Attributes MVC 特性 (ApiResultFilter, Authentication, ModelValidation)
Authorization 授权策略
ApiLog API 日志记录
Http HTTP 客户端封装

3. 数据库 (Databse)

模块 说明
Db 数据库连接封装,支持事务
Dp Dapper 扩展 (CRUD, 批量操作)
EF EntityFramework Core 支持
Infrastructure 数据库基础设施 (多方言支持)

支持的数据库: MySQL, Oracle, SQLServer 等

4. 文件处理 (File)

模块 说明
Compress 压缩解压 (Zip, GZip)
NPOI Excel/Word 读写
Aspose Aspose.Words 文档处理
Spire Spire.Doc 文档处理
Common 通用文件操作
HtmlToOpenXml HTML 转 Word

5. 云服务集成

腾讯云 (Tencent)
服务 说明
Cos 对象存储 (COS)
Sms 短信服务
Captcha 验证码 (WebApp/小程序)
WeXin 微信消息推送、认证
WxPay 微信支付
TokenHub Token 管理
阿里云 (Alibaba)
服务 说明
Ocr OCR 文字识别
AddressPurification 地址解析服务

6. 第三方服务

服务 说明
QiChaCha 企查查 - 企业信息查询
TianYanCha 天眼查 - 企业信息查询
Weather 和风天气 API

7. 消息队列 (Mq)

  • RabbitMQ 集成
  • 发布/订阅模式支持

8. 任务调度 (TaskSchedule)

  • Hangfire 集成
  • Quartz 定时任务

9. 反爬虫/防护 (AntiScraping)

  • IP 限流
  • 客户端限流
  • 代理头处理

10. 日志系统 (Logger)

  • Serilog 结构化日志
  • LogDashboard 日志仪表盘
  • 请求日志中间件

快速开始

安装

dotnet add package NetKernel.DotNetForge

服务注册

Program.cs 中使用扩展方法注册服务:

using DotNetForge.Extensions;

var builder = WebApplication.CreateBuilder(args);

// 添加 JSON 配置
builder.Configuration.AddJsonSetting("appsettings.json");

// JWT 认证
builder.Services.AddJwtAuthentication<Authenticator>(options =>
{
    options.Secret = "your-secret-key";
    options.ExpireMinutes = 30;
});

// Web API
builder.Services.AddWebApi();

// 腾讯云服务
builder.Services.AddTencentCos(builder.Configuration);
builder.Services.AddTencentSms(builder.Configuration);

// 阿里云服务
builder.Services.AddOcr(builder.Configuration);

// 数据库
builder.Services.AddMQ(builder.Configuration);

// 任务调度
builder.Services.AddHangfire(builder.Configuration);

// 日志
builder.Services.AddSerilog(builder.Configuration);

var app = builder.Build();

数据库操作

using var db = new Db("ConnectionString");

// 查询
var users = await db.QueryAsync<User>("SELECT * FROM Users");

// Dapper 扩展
var user = await db.GetAsync<User>(id);

// 事务
using var transaction = db.BeginTransaction();
try
{
    db.Execute("INSERT INTO Logs (Message) VALUES (@Message)", new { Message = "test" });
    transaction.Commit();
}
catch
{
    transaction.Rollback();
}

JWT 认证

// 生成 Token
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.PutObject("file.txt", "local/path.txt");

项目结构

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 Office 文档
云服务 TencentCloudSDK, AlibabaCloud 腾讯/阿里云
消息队列 RabbitMQ.Client RabbitMQ
调度 Hangfire, Quartz 定时任务
日志 Serilog, LogDashboard 日志记录
安全 JwtBearer JWT 认证
其他 AutoMapper, Newtonsoft.Json 工具库

License

MIT License

Product 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.

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
1.0.0.1 86 5/18/2026
1.0.0 86 5/18/2026