کتابخانه ای برای ایجاد Interception در EF به زبان ساده تر
200, OK
https://github.com/khellang/EF.Interception icon
public class AuditInterceptor : Interceptor<IAuditEntity>
{
    public override void PreInsert(IContext<IAuditEntity> context)
    {
        context.Entity.CreatedAt = DateTime.UtcNow;
        context.Entity.ModifiedAt = DateTime.UtcNow;
    }

    public override void PreUpdate(IContext<IAuditEntity> context)
    {
        context.Entity.ModifiedAt = DateTime.UtcNow;
    }
}

public class MyDbContext : InterceptionDbContext
{
    public MyDbContext()
    {
        AddInterceptor(new AuditInterceptor());
    }
}
کتابخانه ای برای ایجاد Interception در EF به زبان ساده تر