Pandatech.AuditTrail
0.0.8
We have newer version
dotnet add package Pandatech.AuditTrail --version 0.0.8
NuGet\Install-Package Pandatech.AuditTrail -Version 0.0.8
<PackageReference Include="Pandatech.AuditTrail" Version="0.0.8" />
paket add Pandatech.AuditTrail --version 0.0.8
#r "nuget: Pandatech.AuditTrail, 0.0.8"
// Install Pandatech.AuditTrail as a Cake Addin #addin nuget:?package=Pandatech.AuditTrail&version=0.0.8 // Install Pandatech.AuditTrail as a Cake Tool #tool nuget:?package=Pandatech.AuditTrail&version=0.0.8
Pandatech.***
Introduction
Pandatech.AuditTrail is a tool meticulously crafted to gather vital entity data from the change tracker post DbContext SaveChanges operation.
Features
Audits necessary entities for logging or preserving modified property data. Offers a convenient fluent configuration to specify tracked entities with ease.
Installation
Install the package via NuGet Package Manager or use the following command:
Install-Package Pandatech.AuditTrail
Configuration
- Implement the
IAuditTrailConsumer
interface. To be able to retrive modified entities data after save operation.
public class AuditTrailConsumer<TPermission>() : IAuditTrailConsumer<TPermission>
{
public Task ConsumeAsync(IEnumerable<AuditTrailCommanModel<TPermission>> entities, CancellationToken cancellationToken = default)
{
}
}
- Add required services.
builder.Services.AddAuditTrailFromAssembly(typeof(AssemblyReference).Assembly);
builder.Services.AddScoped<IAuditTrailService<PermissionType?>, AuditTrailService<PermissionType?>>();
builder.Services.AddScoped<IAuditTrailConsumer<PermissionType?>, AuditTrailConsumer<PermissionType?>>();
//Optional only for properties that encrypted to byte[] and require Decryption.
builder.Services.AddScoped<IAuditTrailDecryption, AuditTrailDecryption>();
services.AddSingleton<AuditTrailSaveInterceptor<PermissionType?>>();
services.AddSingleton<AuditTrailDbTransactionInterceptor<PermissionType?>>();
services.AddDbContextPool<PostgresContext>((sp, options) =>
{
var auditSaveInterceptor = sp.GetRequiredService<AuditTrailSaveInterceptor<PermissionType?>>();
var auditDbTransactionInterceptor = sp.GetRequiredService<AuditTrailDbTransactionInterceptor<PermissionType?>>();
options.UseNpgsql(connectionString)
.AddInterceptors(auditSaveInterceptor)
.AddInterceptors(auditDbTransactionInterceptor);
});
Usage
Create a rule derived from EntityRule
.
public class UserRule : EntityRule<UserEntity, PermissionType?>
{
public UserRule(ISomeService someService)
{
SetPermission(PermissionType.Users_Read);
RuleFor(s => s.PasswordHash).Ignore();
RuleFor(s => s.Status).ChangeName("UserStatus");
}
}
You can create your own rules and modify properties as needed. Custom rule example:
public class ChangeNamePropertyRule<TEntity, TProperty> : PropertyRule<TEntity, TProperty>
{
private readonly string _changeName;
public override NameValue ExecuteRule(string name, object value)
{
return new NameValue(_changeName, value);
}
public ChangeNamePropertyRule(string name)
{
_changeName = name;
}
}
public static class RuleExtensions
{
public static IRuleBulder<T, TPermission, TProperty?> ChangeName<T, TPermission, TProperty>(this IRuleBulder<T, TPermission, TProperty> ruleBuilder, string name)
where T : class
{
var rule = new ChangeNamePropertyRule<T, TProperty?>(name);
return ruleBuilder.SetRule(rule!)!;
}
}
Limitations
Only numeric entity IDs are assigned during SaveChanges. Composite keys are not supported.
License
Pandatech.*** is licensed under the MIT License.
Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
Added package