Bium.Auditing.Contracts.Extensions
1.0.2
dotnet add package Bium.Auditing.Contracts.Extensions --version 1.0.2
NuGet\Install-Package Bium.Auditing.Contracts.Extensions -Version 1.0.2
<PackageReference Include="Bium.Auditing.Contracts.Extensions" Version="1.0.2" />
<PackageVersion Include="Bium.Auditing.Contracts.Extensions" Version="1.0.2" />
<PackageReference Include="Bium.Auditing.Contracts.Extensions" />
paket add Bium.Auditing.Contracts.Extensions --version 1.0.2
#r "nuget: Bium.Auditing.Contracts.Extensions, 1.0.2"
#:package Bium.Auditing.Contracts.Extensions@1.0.2
#addin nuget:?package=Bium.Auditing.Contracts.Extensions&version=1.0.2
#tool nuget:?package=Bium.Auditing.Contracts.Extensions&version=1.0.2
Bium.Auditing.Contracts.Extensions

Bium.Auditing.Contracts.Extensions
provides a comprehensive set of reusable extension methods for auditing entities in .NET applications. It simplifies managing creation, modification, deletion, soft delete metadata, and user tracking on entities implementing standard auditing interfaces.
Features
Creation Audit Extensions (CreationAuditExtensions
)
SetCreated<TPrimaryKey>(entity, createdBy)
Sets creation metadata (CreatedAt
andCreatedBy
) using the current UTC time.SetCreated<TPrimaryKey, TDateTime>(entity, createdBy, createdAt)
Sets creation metadata with a specified timestamp.
Creation Time Extensions (CreationTimeExtensions
)
SetCreatedNow(entity)
Sets the creation time to current UTC (DateTime
orDateTimeOffset
).SetCreatedAt<TDateTime>(entity, createdAt)
Sets a specific creation time.
Creator ID Extensions (CreatorIdExtensions
)
SetCreatedBy<TPrimaryKey>(entity, createdBy)
Sets theCreatedBy
property.
Modification Audit Extensions (ModificationAuditExtensions
)
SetModified<TPrimaryKey>(entity, modifiedBy)
Sets modification metadata using current UTC time (DateTime
orDateTimeOffset
).SetModified<TPrimaryKey, TDateTime>(entity, modifiedBy, modifiedAt)
Sets modification metadata with a specified timestamp.
Modification Time Extensions (ModificationTimeExtensions
)
SetModifiedNow(entity)
Sets modification time to current UTC.SetModifiedAt<TDateTime>(entity, modifiedAt)
Sets a specific modification time.
Modifier ID Extensions (ModifierIdExtensions
)
SetModifiedBy<TPrimaryKey>(entity, modifiedBy)
Sets theModifiedBy
property.
Deletion Audit Extensions (DeletionAuditExtensions
)
SetDeleted<TPrimaryKey>(entity, deletedBy)
Sets deletion metadata (DeletedAt
,DeletedBy
,IsDeleted
) using current UTC time.SetDeleted<TPrimaryKey, TDateTime>(entity, deletedBy, deletedAt)
Sets deletion metadata with a specified timestamp.
Deletion Time Extensions (DeletionTimeExtensions
)
SetDeletedNow(entity)
Sets deletion time to current UTC and marks entity as deleted.SetDeletedAt<TDateTime>(entity, deletedAt)
Sets a specific deletion time and marks entity as deleted.
Deleter ID Extensions (DeleterIdExtensions
)
SetDeletedBy<TPrimaryKey>(entity, deletedBy)
Sets theDeletedBy
property and marks the entity as deleted.
Soft Delete Extensions (SoftDeleteExtensions
)
SetIsDeleted(entity)
Marks the entity as soft deleted (IsDeleted = true
).
Audit Kind Extensions (AudtiKindExtensions
)
TryApplyCreationTime(entity)
Attempts to set the creation time to the current UTC time. Returnstrue
if the entity supports creation time, otherwisefalse
.TryApplyCreationTime<TDateTime>(entity, createdAt)
Attempts to set a specific creation time. Returnstrue
if supported, otherwisefalse
.TryApplyModificationTime(entity)
Attempts to set the modification time to the current UTC time. Returnstrue
if the entity supports modification time, otherwisefalse
.TryApplyModificationTime<TDateTime>(entity, modifiedAt)
Attempts to set a specific modification time. Returnstrue
if supported, otherwisefalse
.TryApplyDeletionTime(entity)
Attempts to set the deletion time to the current UTC time. Returnstrue
if the entity supports deletion time, otherwisefalse
.TryApplyDeletionTime<TDateTime>(entity, deletedAt)
Attempts to set a specific deletion time. Returnstrue
if supported, otherwisefalse
.TryApplySoftDelete(entity)
Attempts to mark the entity as soft deleted. Returnstrue
if the entity supports soft delete, otherwisefalse
.TryApplyCreatorId<TPrimaryKey>(entity, createdBy)
Attempts to set the creator identifier. Returnstrue
if supported, otherwisefalse
.TryApplyModifierId<TPrimaryKey>(entity, modifiedBy)
Attempts to set the modifier identifier. Returnstrue
if supported, otherwisefalse
.TryApplyDeleterId<TPrimaryKey>(entity, deletedBy)
Attempts to set the deleter identifier. Returnstrue
if supported, otherwisefalse
.
Getting Started
Here’s a set of example usages for all the auditing extension methods:
using Bium.Auditing.Contracts.Extensions;
using System;
class Program
{
static void Main()
{
// Example entity implementing auditing interfaces
var entity = new MyEntity(); // Assume MyEntity implements IAuditKind, ISoftDeletable, etc.
// -------------------------
// Creation Audit Extensions
// -------------------------
entity.SetCreatedNow(); // Sets CreatedAt to DateTime.UtcNow
entity.SetCreatedBy(1001); // Sets CreatedBy
entity.SetCreated(1001, DateTime.UtcNow.AddMinutes(-10)); // Sets CreatedBy and custom CreatedAt
// -------------------------
// Modification Audit Extensions
// -------------------------
entity.SetModifiedNow(); // Sets ModifiedAt to DateTime.UtcNow
entity.SetModifiedBy(2002); // Sets ModifiedBy
entity.SetModified(2002, DateTime.UtcNow.AddMinutes(-5)); // Sets ModifiedBy and custom ModifiedAt
// -------------------------
// Deletion Audit Extensions
// -------------------------
entity.SetDeletedNow(); // Sets DeletedAt to DateTime.UtcNow and IsDeleted = true
entity.SetDeletedBy(3003); // Sets DeletedBy and IsDeleted = true
entity.SetDeleted(3003, DateTime.UtcNow.AddMinutes(-1)); // Sets DeletedBy and custom DeletedAt
// -------------------------
// Soft Delete
// -------------------------
entity.SetIsDeleted(); // Marks the entity as soft deleted
// -------------------------
// AuditKind Extensions
// -------------------------
IAuditKind auditEntity = entity;
bool applied;
applied = auditEntity.TryApplyCreationTime(); // Sets CreatedAt to UTC now if supported
applied = auditEntity.TryApplyCreationTime(DateTime.UtcNow.AddHours(-1)); // Sets custom CreatedAt
applied = auditEntity.TryApplyModificationTime(); // Sets ModifiedAt to UTC now
applied = auditEntity.TryApplyModificationTime(DateTime.UtcNow.AddHours(-2)); // Sets custom ModifiedAt
applied = auditEntity.TryApplyDeletionTime(); // Sets DeletedAt to UTC now
applied = auditEntity.TryApplyDeletionTime(DateTime.UtcNow.AddHours(-3)); // Sets custom DeletedAt
applied = auditEntity.TryApplySoftDelete(); // Sets IsDeleted = true
applied = auditEntity.TryApplyCreatorId(1001); // Sets CreatedBy
applied = auditEntity.TryApplyModifierId(2002); // Sets ModifiedBy
applied = auditEntity.TryApplyDeleterId(3003); // Sets DeletedBy
}
}
// Example entity definition for demonstration
public class MyEntity : IAuditable<int, DateTime>
{
public DateTime CreatedAt { get; set; }
public int CreatedBy { get; set; }
public DateTime ModifiedAt { get; set; }
public int ModifiedBy { get; set; }
public DateTime DeletedAt { get; set; }
public int DeletedBy { get; set; }
public bool IsDeleted { get; set; }
}
Notes
- All
Set*
methods update the entity directly. - All
TryApply*
methods return abool
indicating whether the operation was applied (useful if the entity doesn’t implement the expected interface). - The examples demonstrate both default UTC timestamps and custom timestamps.
Contributing
Contributions are welcome! Please follow the standard GitHub workflow:
- Fork the repository
- Create a new branch (
feature/your-feature
) - Commit your changes
- Open a pull request
License
Bium.Auditing.Contracts.Extensions
is licensed under the MIT License.
Product | Versions 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. |
-
.NETStandard 2.1
- Bium.Auditing.Contracts (>= 1.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bium.Auditing.Contracts.Extensions:
Package | Downloads |
---|---|
Bium.Auditing.EntityFrameworkCore
Automatic auditing for EF Core entities, supporting creation, modification, deletion, soft delete, and user tracking. |
GitHub repositories
This package is not used by any popular GitHub repositories.
- Added package icon.