DcsvIo.D2.DataGovernance.Abstractions 0.2.11

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

DcsvIo.D2.DataGovernance.Abstractions

Audience: backend .NET service engineers decorating entity models with GDPR anonymization markers and referencing the engine seam - without pulling in EF Core or DI.

GDPR-anonymization markers, the [Anonymizable] attribute, and the engine seam, with no EF Core and no DI dependency. The EF Core engine implementation is in the sibling DcsvIo.D2.DataGovernance.EntityFrameworkCore library.

Install

dotnet add package DcsvIo.D2.DataGovernance.Abstractions

Purpose

Every D2 service that stores user or org PII needs a uniform, auditable way to erase that data on demand. This library defines the vocabulary every layer shares: ownership markers (IUserOwned, IOrgOwned), an opt-out marker (IExemptFromAnonymization), a provable-completion marker (IAnonymizationTrackable), the field-decoration attribute ([Anonymizable]), the shared rule value object (AnonymizationRule), and the engine seam (IAnonymizationEngine + AnonymizationOutcome).

Domain and host code take a dependency on this library to reference the seam and the markers without pulling in EF Core. All implementation details - the attribute-mapping EF convention, the fluent API, the tiered engine, the startup guard, and DI registration - are in DcsvIo.D2.DataGovernance.EntityFrameworkCore.

This library uses the term anonymization throughout. It is separate from [RedactData], which governs log-masking only. Do not confuse log-masking with anonymization.

Public API surface

Ownership and trackable markers

Interface Members Purpose
IUserOwned Guid? UserId { get; } Entity is owned by a user subject. Engine filters on this id.
IOrgOwned Guid? OrgId { get; } Entity is owned by an org subject. Engine filters on this id.
IExemptFromAnonymization (empty marker) Engine skips this entity type entirely - no field is ever overwritten even if decorated. Counted in AnonymizationOutcome.EntityTypesSkippedExempt.
IAnonymizationTrackable bool IsAnonymized { get; } Engine sets this to true via EF Core when overwriting a row; excludes already-anonymized rows on re-run for idempotency. Mandatory on any ownership-marked entity that carries [Anonymizable] fields.

The UserId / OrgId properties are Guid? (nullable) because rows may be created before ownership is assigned. The engine skips rows where the ownership id is null.

An entity may implement both IUserOwned and IOrgOwned simultaneously.

[Anonymizable] attribute

Decorates an entity property to declare its per-field anonymization strategy. Consumed by the EF Core model convention at model-build time.

Call-site forms
Usage Resulting AnonymizationRule
[Anonymizable(AnonymizeKind.SetNull)] Kind = SetNull
[Anonymizable(AnonymizeKind.SetEmpty)] Kind = SetEmpty
[Anonymizable("tombstone")] Kind = Constant, ConstantValue = "tombstone"
[Anonymizable(template: "deletedUser{UserId}@deleted.user.dcsv.io")] Kind = Template, Template = "deletedUser{UserId}@..."

The bare positional string is always a constant. The template: named argument selects the template overload, so never pass AnonymizeTemplateMarker explicitly: the template: named argument selects the ctor and the compiler infers the discriminator. Constructing the attribute in a contradictory state (e.g. AnonymizeKind.Constant with no value) throws ArgumentException at model-build time - this is a developer configuration error, not a runtime validation failure.

[Anonymizable("")] is accepted as Constant(""). The engine treats Constant("") and SetEmpty identically at apply-time; they remain distinct rules so the startup divergence guard can detect unintentional double-declarations.

This attribute is strictly separate from [RedactData] (log-masking). They govern independent concerns - applying both to the same property is allowed. When both an [Anonymizable] attribute and a fluent declaration target the same property, fluent wins (Explicit > DataAnnotation EF Core precedence). Identical attribute + fluent values are accepted; a divergent pair (different Kind or payload) is detected by the startup guard as a configuration error.

[KeepOnAnonymization] attribute

KeepOnAnonymizationAttribute records that a property holding personal data is kept on purpose when its subject is erased, and why. It is the other half of the declaration that AnonymizableAttribute makes: AnonymizableAttribute says how a column is overwritten, and KeepOnAnonymizationAttribute says why a column is not.

[KeepOnAnonymization("tombstoned by the aggregate's own delete transition")]
public required string Email { get; set; }

The engine does not read this attribute and its behavior does not change. The marker exists so a consumer's own completeness check can tell a column deliberately retained from one nobody declared - without it the two are indistinguishable to every reader. Reason is required and non-empty; an empty one throws ArgumentException where the attribute is declared.

It is not a substitute for [Anonymizable]. A property carrying both declares a rule the engine applies and a reason to keep it, which is a contradiction. The consumer's own check is where to catch it.

AnonymizeKind enum

Closed set of overwrite strategies:

Member Underlying value Meaning
SetNull 0 Overwrite with null (column must be nullable).
SetEmpty 1 Overwrite with "" (column must be a string type).
Constant 2 Overwrite with a fixed developer-supplied tombstone string.
Template 3 Overwrite with a computed tombstone using {FieldName} sibling interpolation (resolved at erasure time). Guid values rendered without dashes.

AnonymizationRule record

Immutable value object carrying Kind, ConstantValue?, Template?. Written by the EF Core model convention or the fluent mapping API as the D2:Anonymize EF model annotation; read by the anonymization engine at runtime.

Construction via AnonymizationRule.Create(kind, constantValue, template) - the factory enforces the same Kind <-> payload invariant as the attribute ctor. Constant("") != SetEmpty by record equality (different Kind), even though the engine treats them identically at apply-time.

AnonymizationOutcome record

Immutable success payload returned by IAnonymizationEngine. Its required init counters:

Property Meaning
EntityTypesProcessed Distinct entity CLR types examined (ownership-marked, not exempt).
RowsAnonymized Total rows overwritten in this sweep.
EntityTypesSkippedExempt Distinct entity CLR types skipped (IExemptFromAnonymization).
AlreadyAnonymizedRows Rows excluded because IsAnonymized was already true.

A zero-valued outcome (all counters at 0) is valid - no failure. The engine returns Ok(outcome-with-zeros) when no rows matched the subject id.

IAnonymizationEngine - engine seam

Task<D2Result<AnonymizationOutcome>> AnonymizeUserAsync(Guid userId, CancellationToken ct = default);
Task<D2Result<AnonymizationOutcome>> AnonymizeOrgAsync(Guid orgId, CancellationToken ct = default);
  • Guid.Empty → D2Result.ValidationFailed, no database writes.
  • Idempotent - rows where IsAnonymized == true are skipped.
  • Always Task (not ValueTask) - the engine always does real async DB I/O.
  • Implementation: DcsvIo.D2.DataGovernance.EntityFrameworkCore.

Dependencies

Dependency Why
DcsvIo.D2.Result IAnonymizationEngine returns Task<D2Result<AnonymizationOutcome>>.
JetBrains.Annotations [UsedImplicitly] on AnonymizableAttribute's reflectively-consumed properties (Kind, ConstantValue, Template). Does not flow transitively from DcsvIo.D2.Result so an explicit reference is required.

The library also references DcsvIo.D2.Utilities: KeepOnAnonymizationAttribute uses Falsey() to check its reason argument.

Tests

Unit tests covering the full public API surface live in the DcsvIo.D2.Tests DataGovernance abstractions unit suite.

Coverage includes every [Anonymizable] constructor form and adversarial input (null/empty constant, whitespace template, undefined enum value, contradictory Kind/payload combinations), AnonymizationRule.Create invariant enforcement, AnonymizationOutcome construction, the marker interfaces via test implementations, and IAnonymizationEngine contract shape (return type, parameter names, default CancellationToken).

Telemetry

No telemetry surface - foundation lib emits no spans or metrics. Consumers instrument the anonymization call sites in their own OTel setup.

Configuration

No configuration - zero-config; the contracts and markers have no tunable behavior.

References

  • Sibling implementation library: DcsvIo.D2.DataGovernance.EntityFrameworkCore
  • Analogous pattern: DcsvIo.D2.Caching.Abstractions - same marker-interface + seam structure
  • ADR-0015 (docs/adrs/0015-anonymization-data-governance.md) - anonymization / data-governance architecture
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 DcsvIo.D2.DataGovernance.Abstractions:

Package Downloads
DcsvIo.D2.DataGovernance.EntityFrameworkCore

EF Core wiring for D2 GDPR anonymization - the fluent .Anonymize* API, the engine registration, and the startup model guard.

DcsvIo.D2.Outbox.EntityFrameworkCore

EF Core storage for the D2 transactional outbox.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.11 160 10/26/2026
0.1.1 170 7/17/2026
0.1.0 169 7/17/2026