Bium.Auditing.Contracts 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Bium.Auditing.Contracts --version 1.0.1
                    
NuGet\Install-Package Bium.Auditing.Contracts -Version 1.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="Bium.Auditing.Contracts" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bium.Auditing.Contracts" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bium.Auditing.Contracts" />
                    
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 Bium.Auditing.Contracts --version 1.0.1
                    
#r "nuget: Bium.Auditing.Contracts, 1.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 Bium.Auditing.Contracts@1.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=Bium.Auditing.Contracts&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Bium.Auditing.Contracts&version=1.0.1
                    
Install as a Cake Tool

Bium.Auditing.Contracts NuGet version (Bium.Auditing.Contracts) NuGet Downloads

Bium.Auditing.Contracts provides a set of standardized contracts (interfaces) for auditing entities in .NET applications. It allows developers to implement creation, modification, and deletion auditing consistently across their domain entities, supporting both timestamp-only auditing and full actor (user) auditing with navigation references.

Features

  • Marker Interfaces:

    • IAuditKind – Identifies auditable entities.
    • IEntityKind – Marks domain entities.
  • Creation Auditing:

    • IHasCreationTime<TDateTime> – Tracks creation timestamp.
    • IHasCreatorId<TPrimaryKey> – Tracks creator by ID.
    • IHasCreator<TUser, TPrimaryKey> – Tracks creator entity reference.
    • ICreationAudited<TPrimaryKey, TDateTime> – Combines creation time + creator ID.
    • ICreationAudited<TUser, TPrimaryKey, TDateTime> – Combines creation time + creator entity + ID.
  • Modification Auditing:

    • IHasModificationTime<TDateTime> – Tracks last modification timestamp.
    • IHasModifierId<TPrimaryKey> – Tracks last modifier by ID.
    • IHasModifier<TUser, TPrimaryKey> – Tracks last modifier entity reference.
    • IModificationAudited<TPrimaryKey, TDateTime> – Combines modification time + modifier ID.
    • IModificationAudited<TUser, TPrimaryKey, TDateTime> – Combines modification time + modifier entity + ID.
  • Deletion Auditing & Soft Delete:

    • ISoftDeletable – Supports soft deletion via IsDeleted.
    • IHasDeletionTime<TDateTime> – Tracks deletion timestamp.
    • IHasDeleterId<TPrimaryKey> – Tracks deleter by ID.
    • IHasDeleter<TUser, TPrimaryKey> – Tracks deleter entity reference.
    • IDeletionAudited<TPrimaryKey, TDateTime> – Combines deletion time + deleter ID.
    • IDeletionAudited<TUser, TPrimaryKey, TDateTime> – Combines deletion time + deleter entity + ID.
  • Composite Auditing:

    • IAuditable<TDateTime> – Timestamp-only auditing (creation, modification, deletion).
    • IAuditable<TPrimaryKey, TDateTime> – Timestamp + actor ID auditing.
    • IAuditable<TUser, TPrimaryKey, TDateTime> – Full auditing with navigation to user entities.
  • Auditable Entities:

    • IAuditableEntity<TPrimaryKey, TDateTime> – Base contract for entities with primary key + auditing.
    • IAuditableEntity<TUser, TPrimaryKey, TDateTime> – Base contract with user references for full actor auditing.
  • Generic Primary Keys <TPrimaryKey>: Support for flexible primary key types (int, long, Guid, etc.).

  • Timestamp Flexibility <TDateTime>: Supports DateTime or DateTimeOffset for creation/modification/deletion times.

  • Highly Customizable: Extend or implement granular interfaces to fit your domain model and auditing requirements.

Getting Started

1. IAuditable

1.1 Timestamp-Only Auditing
using Bium.Auditing.Contracts;

public class Product : IAuditable<DateTime>
{
    public DateTime CreatedAt { get; set; }
    public DateTime? ModifiedAt { get; set; }
    public DateTime? DeletedAt { get; set; }
    public bool IsDeleted { get; set; }
}
1.2 Actor ID Auditing
using Bium.Auditing.Contracts;

public class Order : IAuditable<Guid, DateTimeOffset>
{
    public DateTimeOffset CreatedAt { get; set; }
    public Guid CreatedBy { get; set; }

    public DateTimeOffset? ModifiedAt { get; set; }
    public Guid? ModifiedBy { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
    public bool IsDeleted { get; set; }
    public Guid? DeletedBy { get; set; }
}
1.3 Full Actor Auditing (with user entity references)
using Bium.Auditing.Contracts;

public class AppUser : IEntity<Guid>
{
    public Guid Id { get; set; }
    public string UserName { get; set; } = string.Empty;
}

public class Order : IAuditable<AppUser, Guid, DateTimeOffset>
{
    public DateTimeOffset CreatedAt { get; set; }
    public Guid CreatedBy { get; set; }
    public AppUser Creator { get; set; } = null!;

    public DateTimeOffset? ModifiedAt { get; set; }
    public Guid? ModifiedBy { get; set; }
    public AppUser? Modifier { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
    public bool IsDeleted { get; set; }
    public Guid? DeletedBy { get; set; }
    public AppUser? Deleter { get; set; }
}

2. IAuditableEntity

2.1 Timestamp-Only Auditing
using Bium.Auditing.Contracts;

public class Product : IAuditableEntity<DateTime>
{
    public Guid Id { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime? ModifiedAt { get; set; }
    public DateTime? DeletedAt { get; set; }
    public bool IsDeleted { get; set; }
}
2.2 Full Actor Auditing
using Bium.Auditing.Contracts;

public class AppUser : IEntity<Guid>
{
    public Guid Id { get; set; }
    public string UserName { get; set; } = string.Empty;
}

public class Order : IAuditableEntity<AppUser, Guid, DateTimeOffset>
{
    public Guid Id { get; set; }

    public DateTimeOffset CreatedAt { get; set; }
    public Guid CreatedBy { get; set; }
    public AppUser Creator { get; set; } = null!;

    public DateTimeOffset? ModifiedAt { get; set; }
    public Guid? ModifiedBy { get; set; }
    public AppUser? Modifier { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
    public bool IsDeleted { get; set; }
    public Guid? DeletedBy { get; set; }
    public AppUser? Deleter { get; set; }
}

Why struct for TPrimaryKey?

All primary key types (TPrimaryKey) in Bium.Auditing.Contracts are constrained to struct for multiple important reasons:

  1. Value Type Semantics

    • struct ensures that the primary key is a value type rather than a reference type.
    • Value types are immutable by default, which reduces unintended side effects in your entities and ensures predictable behavior for equality and hashing.
  2. Performance Benefits

    • Value types are allocated on the stack (or inlined in objects for fields), avoiding heap allocations that reference types incur.
    • Operations such as equality checks, comparisons, and dictionary lookups are faster for value types like int, long, or Guid.
  3. Consistency Across ORMs

    • Most ORMs, including Entity Framework Core, assume primary keys are value types for generating database keys and relationships.
    • Using value types avoids potential issues with nullability, reference equality, and serialization.
  4. Compile-Time Safety

    • Constraining to struct prevents accidental use of reference types (like string, object, or custom classes) as primary keys.
    • This ensures that entities always use lightweight, comparable, and immutable types for IDs, preventing runtime errors or inconsistent behavior.
  5. Supports Nullable IDs Where Needed

    • Nullable value types (Guid?, int?, etc.) allow tracking of unset or optional relationships while still enforcing type safety.
    • For example, DeletedBy or ModifiedBy can be null to indicate no action yet.
  6. Broad Compatibility

    • struct covers all typical primary key types used in databases:

      • int or long for auto-increment keys.
      • Guid for distributed unique identifiers.
      • short, byte, or other numeric types when required.
    • This makes the auditing interfaces highly generic and reusable.

Summary: Constraining TPrimaryKey to struct ensures safety, performance, and consistency while providing flexibility for common database primary key types, making it ideal for enterprise-grade auditing systems.

Contributing

Contributions are welcome! Please follow the standard GitHub workflow:

  1. Fork the repository
  2. Create a new branch (feature/your-feature)
  3. Commit your changes
  4. Open a pull request

License

Bium.Auditing.Contracts is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bium.Auditing.Contracts:

Package Downloads
Bium.Auditing.Contracts.Extensions

Extension methods for auditing entities, supporting creation, modification, deletion, soft delete, and tracking creators, modifiers, and deleters.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 0 9/18/2025
1.0.2 29 9/17/2025
1.0.1 46 9/15/2025
1.0.0 39 9/15/2025

- Updated README and LICENSE file.