Skip to content

Latest commit

 

History

History

Ling.Audit

Ling.Audit

Introduction

Ling.Audit is a source generator for audit properties.

Installation

You can install Ling.Audit using either Package Manager or .NET CLI.

  1. Package Manager
PM> Install-Package Ling.Audit
  1. .NET CLI
dotnet add package Ling.Audit

Usage

To use Ling.Audit, follow these steps:

  1. Create your class with the partial keyword and implement the necessary interfaces:
  • IHasCreationTime
  • IHasCreator<T>
  • ICreationAudited<T>
  • IHasModificationTime
  • IHasModifier<T>
  • IModificationAudited<T>
  • ISoftDelete
  • IHasDeletionTime
  • IHasDeleter<T>
  • IDeletionAudited<T>
  • IFullAudited<T>

Here's an example of how to implement these interfaces in a class called Post:

public partial class Post : IFullAudited<Guid>
{
	public int Id { get; set; }
	public string Title { get; set; } = null!;
	...
}

This will generate the following properties for the Post class:

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace WebApplication1.Entities
{
    public partial class Post
    {
        /// <summary>
        /// Gets or sets the creation time of this entity.
        /// </summary>
        public virtual global::System.DateTimeOffset CreationTime { get; set; }
    
        /// <summary>
        /// Gets or sets the creator Id of this entity.
        /// </summary>
        public virtual global::System.Nullable<global::System.Guid> CreatorId { get; set; }
    
        /// <summary>
        /// Gets or sets the last modification time of this entity.
        /// </summary>
        public virtual global::System.Nullable<global::System.DateTimeOffset> LastModificationTime { get; set; }
    
        /// <summary>
        /// Gets or sets the last modifier Id of this entity.
        /// </summary>
        public virtual global::System.Nullable<global::System.Guid> LastModifierId { get; set; }
    
        /// <summary>
        /// Gets or sets whether this entity is soft deleted.
        /// </summary>
        public virtual global::System.Boolean IsDeleted { get; set; }
    
        /// <summary>
        /// Gets or sets the deletion time of this entity.
        /// </summary>
        public virtual global::System.Nullable<global::System.DateTimeOffset> DeletionTime { get; set; }
    
        /// <summary>
        /// Get or set the deleter Id of this entity.
        /// </summary>
        public virtual global::System.Nullable<global::System.Guid> DeleterId { get; set; }
    }
}
  1. If you are using EntityFrameworkCore, you can easily audit and save the entity to the database with Ling.EntityFrameworkCore.Audit.

License

This project is licensed under the Apache 2.0 license.