Galosys.Foundation.Compliance 26.9.16.1

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

Galosys.Foundation.Compliance

合规能力核心包:数据分类 + EntityChanges 字段级 diff + 脱敏辅助 + 合规等级。零破坏性变更,薄层引用现有 Microsoft.Extensions.Compliance.RedactionGalosys.Foundation.Core 资产。

设计文档:能力缺口与行动清单 §行动 1 Phase 1 路线图:合规能力路线图 §Phase 1 决策指南:业务方按本文档「## 快速开始」+「## 特性」段落地

特性

  • 数据分类:5 个内置分类(PrivateData / PublicData / SensitiveData / FinancialData(SOX) / HealthData(HIPAA)),沿用 .NET 10 官方 DataClassification 抽象
  • EntityChangesEntityChange record + IEntityChangeInterceptor 抽象 + 基于反射的默认实现(捕获字段级 diff)
  • 脱敏辅助MaskingHelper 静态门面封装 Redactor 子类调用,供 DataMaskConverterSensitiveDataFilter 共同使用
  • 合规等级ComplianceLevel 三档(Lenient / Standard / Strict)+ ComplianceOptions 配置 + LogTier 四档审计分层
  • DI 集成AddCompliance() 一行注册所有合规服务

快速开始

// Program.cs
using Galosys.Foundation.Compliance;
using Microsoft.Extensions.Compliance.Classification;

var builder = WebApplication.CreateBuilder(args);

// 注册合规服务
builder.Services.AddCompliance(opts =>
{
    opts.Level = ComplianceLevel.Standard;        // Lenient / Standard(默认) / Strict
    opts.LogTier = LogTier.Business;             // Security / Business / System / Debug
    opts.IsEnabled = true;
    opts.ExcludedActions = new HashSet<string> { "HealthController.Ping" };
});

// 标注实体属性
public class Order
{
    [PrivateData]    public string Phone { get; set; } = "";   // PII
    [SensitiveData]  public string OrderNo { get; set; } = ""; // 业务敏感
    [FinancialData]  public decimal Amount { get; set; }       // SOX 财务
    [HealthData]     public string? Diagnosis { get; set; }    // HIPAA 医疗
    [PublicData]     public string PublicNote { get; set; } = "";
}

脱敏辅助(MaskingHelper

MaskingHelper 静态门面封装 6 个官方 Redactor 调用,供业务代码直接使用:

using Galosys.Foundation.Compliance;

var masked = MaskingHelper.MaskPhone("13800138000");   // "138****8000"
var idcard = MaskingHelper.MaskIdCard("110101199001011234"); // "110101********1234"
var email  = MaskingHelper.MaskEmail("user@example.com");    // "u***@example.com"

字段级 Diff(EntityChange

EntityChange record 携带字段级 diff 完整信息(对标 ABP EntityChange + Hibernate Envers):

public sealed record EntityChange(
    string PropertyName,
    string? OldValue,
    string? NewValue,
    EntityChangeType ChangeType,    // Added / Modified / Deleted
    DataClassification Classification);

捕获规则

  • 仅记录标注了 DataClassification 子类的属性(避免审计日志膨胀)
  • JSON 序列化值(自动处理 null / 原始类型 / 复杂对象)
  • 仅输出原值与新值不相等的字段

典型用法:EF Core SaveChangesInterceptorSavingChangesAsync 阶段调用 CaptureChanges() → 结果写入 AuditLog.Changes JSON 字段。

依赖

用途
Galosys.Foundation.Core Entity<T> 基类 + 中央依赖图根节点
Microsoft.Extensions.Compliance.Redaction .NET 10 官方 Redactor 引擎(薄层引用)

Directory.Packages.props 中央包管理,PackageReference 不指定 Version。

不在本包范围(v1 后续落地)

能力 落地包 Phase 状态
ASP.NET Core 中间件(自动审计) Galosys.Foundation.Compliance.AspNetCore Phase 2 ✅ 完成 (2026-08-24)
EF Core SaveChangesInterceptor 适配 Galosys.Foundation.Compliance.AspNetCore Phase 2 ✅ 完成
Roslyn Analyzer GYS001(未标注 PII) Galosys.Foundation.Compliance.Analyzers Phase 3 ✅ 完成 (2026-08-24)
Strict 模式运行期阻断 Galosys.Foundation.Compliance.AspNetCore Phase 2/3 ✅ 完成

详见 合规能力路线图

测试覆盖

Galosys.Foundation.Compliance.Tests(25 测试全通过):

  • DataClassificationsTest × 6(5 个分类值 + AttributeUsage)
  • EntityChangeTest × 3(record 创建 + JSON 序列化 + enum 值)
  • ComplianceOptionsTest × 5(默认值 + 配置覆盖 + enum 值)
  • AddComplianceTest × 3(DI 注册 + TryAdd 语义)
Product 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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Galosys.Foundation.Compliance:

Package Downloads
Galosys.Foundation.AspNetCore

Galosys.Foundation快速开发库

Galosys.Foundation.Compliance.AspNetCore

Galosys.Foundation快速开发库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.9.16.1 0 9/16/2026
26.9.15.1 48 9/15/2026
26.9.14.1 78 9/14/2026
26.9.10.1 167 9/10/2026
26.9.3.1 182 9/3/2026
26.8.29.1 196 8/31/2026
26.8.26.1 220 8/26/2026
26.8.23.1 96 8/23/2026