Galosys.Foundation.AspNetCore 26.5.15.1

dotnet add package Galosys.Foundation.AspNetCore --version 26.5.15.1
                    
NuGet\Install-Package Galosys.Foundation.AspNetCore -Version 26.5.15.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="Galosys.Foundation.AspNetCore" Version="26.5.15.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.AspNetCore" Version="26.5.15.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.AspNetCore" />
                    
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 Galosys.Foundation.AspNetCore --version 26.5.15.1
                    
#r "nuget: Galosys.Foundation.AspNetCore, 26.5.15.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 Galosys.Foundation.AspNetCore@26.5.15.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=Galosys.Foundation.AspNetCore&version=26.5.15.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.AspNetCore&version=26.5.15.1
                    
Install as a Cake Tool

Galosys.Foundation.AspNetCore

成熟度: 🟢 稳定 — 生产可用,测试充分,活跃维护

简介

Galosys.Foundation.AspNetCore 是 ASP.NET Core 核心扩展模块,提供 MVC 过滤器、身份认证、权限管理、SignalR 中间件等功能。

特性

MVC 过滤器

  • GlobalResponseLoggingResultFilter - 响应日志记录
  • GlobalLogExceptionFilter - 全局异常日志
  • GlobalModelStateValidationActionFilter - 模型状态验证
  • AuditLogAttribute - 审计日志
  • RequestLogAttribute - 请求日志
  • CacheableAttribute - 响应缓存(支持多租户 Key 隔离)
  • CacheEvictAttribute - 缓存清除(支持多租户 Key 隔离)
  • CachePutAttribute - 缓存写入(支持多租户 Key 隔离)
  • IdempotentAttribute - 幂等性验证

身份认证

  • JWT Bearer - JWT 认证支持
  • HttpBasic - HTTP 基本认证
  • ApiKey - API Key 认证

权限管理

  • PermissionAuthorizationHandler - 权限授权处理器
  • PermissionScanner - 权限扫描器
  • DynamicAuthorizationPolicyProvider - 动态授权策略

SignalR

  • SignalR Hub - 实时通信
  • SignalR Client - 客户端支持

中间件

  • GlobalExceptionHandlerMiddleware - 全局异常处理
  • MultiTenancyMiddleware - 多租户支持
  • LoginUserMiddleware - 登录用户中间件
  • CorsMiddleware - CORS 配置

安装

dotnet add package Galosys.Foundation.AspNetCore

使用

注册服务

services.AddAspNetCore(); // 注册所有服务

配置 JWT 认证

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.Authority = "https://auth.example.com";
        options.Audience = "api.example.com";
    });

配置 SignalR

services.AddSignalR();

app.UseEndpoints(endpoints =>
{
    endpoints.MapHubs();
});

使用审计日志

[AuditLog("创建订单")]
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest request)
{
    // 业务逻辑,审计日志自动通过 ReliableLogChannel 异步持久化
}

// 设置审计前后值
HttpContext.SetAuditValues(originalValues, currentValues, targetId);
审计日志持久化

审计日志通过 Tier 2 可靠通道异步持久化,失败自动重试(指数退避,最多 3 次)。需注册通道和实现 IAuditLogRepository

// 注册通道 + 消费者(通常在 Startup 中)
services.AddAuditLogChannel();

// 实现持久化接口
public class AuditLogRepository : IAuditLogRepository
{
    public Task AddAsync(AuditLog auditLog, CancellationToken ct = default)
    {
        // 写入 lc.lc_audit_log 表
    }
}

使用请求日志

[RequestLog("订单API")]
public async Task<IActionResult> ListOrders([FromQuery] OrderQuery query)
{
    // 请求日志自动通过 ObservableLogChannel 批量持久化
}
请求日志持久化

请求日志通过 Tier 1 可观测通道批量持久化。需注册通道和实现 IRequestLogRepository

services.AddRequestLogChannel();

public class RequestLogRepository : IRequestLogRepository
{
    public Task AddRangeAsync(IReadOnlyList<RequestLogCreateInput> inputs, CancellationToken ct = default)
    {
        // 批量写入 lc.lc_api_request_log 表
    }
}

使用登录日志

// 替代旧版 GetUserLoginEvent + publisher.PublishAsync
await HttpContext.PublishLoginLogAsync(realName, status: 1, remark: "登录成功");

登录日志通过 Tier 2 可靠通道持久化。需注册通道和实现 ILoginLogRepositoryAddCore() 内置注册通道)。

使用幂等性验证

[Idempotent]
public async Task<IActionResult> SubmitOrder([FromBody] SubmitOrderRequest request)
{
    // 幂等操作
}

使用缓存 Attribute

// 基本用法 — Cache Key: "dict-type:{表达式结果}"
[Cacheable("dict-type", Key = "query.Code")]
public async Task<UnifiedResponse> GetDictType(DictTypeQuery query) { }

// 多租户隔离 — Cache Key: "dict-type:{tenantId}:{表达式结果}"
[Cacheable("dict-type", Key = "query.Code", TenantAware = true)]
public async Task<UnifiedResponse> GetDictType(DictTypeQuery query) { }

// 缓存清除
[CacheEvict("dict-type", Key = "command.Code", TenantAware = true)]
public async Task<UnifiedResponse> UpdateDictType(UpdateDictTypeCommand command) { }

// 缓存写入
[CachePut("dict-type", Key = "command.Code", TenantAware = true)]
public async Task<UnifiedResponse> CreateDictType(CreateDictTypeCommand command) { }
TenantAware Key 格式
场景 TenantAware TenantId Key 示例
不感知(默认) false dict-type:GZ
感知 + 有租户 true 5 dict-type:5:GZ
感知 + 无租户 true 0 dict-type:global:GZ
感知 + 无 Key 表达式 true 5 dict-type:5

前提:使用 TenantAware=true 需确保已调用 services.AddCore() 注册 ITenantContext

权限控制

[Authorize(Policy = "RequirePermission")]
public async Task<IActionResult> DeleteOrder(string orderNo)
{
    // 需要特定权限
}

SignalR Hub

public class NotificationHub : Hub
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.User(user).SendAsync("ReceiveMessage", message);
    }
}

核心类

分类 说明
Filter GlobalResponseLoggingResultFilter 响应日志过滤器
Filter GlobalLogExceptionFilter 异常日志过滤器
Filter AuditLogAttribute 审计日志特性
Auth JwtHelper JWT 辅助类
Auth HttpBasicAuthenticationHandler HTTP 基本认证
SignalR HubBase Hub 基类
Middleware GlobalExceptionHandlerMiddleware 全局异常处理

依赖

  • Microsoft.AspNetCore.Authentication.JwtBearer
  • Microsoft.AspNetCore.SignalR
  • Galosys.Foundation.Core
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 (9)

Showing the top 5 NuGet packages that depend on Galosys.Foundation.AspNetCore:

Package Downloads
Galosys.Foundation.AspNetCore.DynamicApi

Galosys.Foundation快速开发库

Galosys.Foundation.AspNetCore.Quartz

Galosys.Foundation快速开发库

Galosys.Foundation.AspNetCore.AdminSafe

Galosys.Foundation快速开发库

Galosys.Foundation.AspNetCore.Localization

Galosys.Foundation快速开发库

Galosys.Foundation.AspNetCore.HealthChecks.UI

Galosys.Foundation快速开发库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.5.15.1 44 5/15/2026
26.5.12.3 238 5/12/2026
26.5.12.2 261 5/12/2026
26.4.27.1-rc1 249 4/26/2026
26.4.25.1-rc1 251 4/25/2026
26.4.22.2-rc7 258 4/22/2026
26.4.22.2-rc6 254 4/22/2026
26.4.22.2-rc4 261 4/22/2026
26.4.22.2-rc3 244 4/22/2026
26.4.19.1-rc1 236 4/19/2026
26.1.30.1-rc1 378 1/30/2026
26.1.29.1 398 1/29/2026
26.1.28.5 413 1/28/2026
26.1.28.4 408 1/28/2026
26.1.28.2 406 1/28/2026
26.1.23.6 383 1/23/2026
26.1.21.1 366 1/21/2026
26.1.2.1 376 1/2/2026
26.1.1.1 386 1/1/2026
25.12.12.4 408 12/12/2025
Loading failed