Giter Site home page Giter Site logo

efcore.audit's Introduction

EFCore.Audit

Issues MIT License


Logo

EFCore.Audit

A simple library that adds audit capabilities to the Entity Framework Core.
Report Bug · Request Feature

Table of Contents

About The Project

EFCore.Audit

With this library, you can automatically have an audit mechanism for labeled model classes in EF Core.

Getting Started

To get start with EFCore.Audit you can clone repository or add as a reference to your project from nuget.

Package Manager

Install-Package EFCore.Audit -Version 1.0.0

.NET CLI

dotnet add package EFCore.Audit --version 1.0.0

PackageReference

<PackageReference Include="EFCore.Audit" Version="1.0.0" />

Usage

EFCore.Audit adds audit data by overriding and inserting audit logic. The library has its own audit entities to store audit data. To use EFCore.Audit, as a developer you need to do a couple of things.

  • Since EFCore.Audit override SaveChanges(), you need to inherit your DBContext class from AuditDbContextBase.
public class PersonDbContext :AuditDbContextBase<PersonDbContext>
{
    ...
}
  • You need also provide a class which implements IAuditUserProvider to the base class. This class provides user who did the operation.
public class PersonDbContext :AuditDbContextBase<PersonDbContext>
{
    public PersonDbContex(DbContextOptions<PersonDbContext> options,IAuditUserProvider auditUserProvider) : bas(options, auditUserProvider) { }
}
public class UserProvider : IAuditUserProvider
{
    private readonly IHttpContextAccessor_httpContextAccessor;
    public UserProvider(IHttpContextAccessorhttpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }
    public string GetUser()
    {
        return _httpContextAccessor.HttpContext.UserIdentity.Name;
    }
}
  • Also base class OnModelCreating() method should be called.
public class PersonDbContext :AuditDbContextBase<PersonDbContext>
 {
    ...

     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {
         ...
         base.OnModelCreating(modelBuilder);
     }
 }
  • The last thing is that labeling auditable classes and excluding desired properties of auditable classes. To label which classes will be auditable and which attributes will be excluded, you need to use Auditable attribute for classes and NotAuditable attribute for properties.
[Auditable]
public class PersonEntity
{
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public GenderEnum Gender { get; set; }
    [NotAuditable]
    public string DummyString { get; set; }
}

Roadmap

See the open issues for a list of proposed features (and known issues).

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Doğa Barış Çakmak - [email protected]

Project Link: https://github.com/dogabariscakmak/EFCore.Audit

Created my free logo at LogoMakr.com

efcore.audit's People

Contributors

dogabariscakmak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.