[AutoApply(Behavior.AuditCreate)] insert UserEmail vs UserId

I’ve recently noticed when extending an autoCRUD auto generated service that the WithAudit(Request) extension method uses the userId by default where the auto crud attribute uses the email. Is there a way with the attribute to define using the Id? I see there is a WithAudit version that accepts a string which I could set with the email, but seems like some extra work every time to pull out the email to match. I’d rather actually use the Id by default.

The Apply Generic CRUD Behaviors explains how all the Behavior.* attributes work which is implemented in AuditAutoCrudMetadataFilter.

To override its behavior you could replace it to use your custom implementation that uses a modified copy of the existing AuditAutoCrudMetadataFilter, e.g:

Plugins.Add(new AutoQueryFeature {
    AutoCrudMetadataFilters = new() { MyAuditAutoCrudMetadataFilter }
})

Or create a new behavior and add it:

Plugins.Add(new AutoQueryFeature {
    AutoCrudMetadataFilters = { 
        meta => {
             if (meta.HasAutoApply("MyAuditCreate"))
             {
                 //...
             }
        }
    }
})

Then your DTOs can use your custom behavior instead:

[AutoApply("MyAuditCreate")]

Thanks. Sorry I missed that in the docs. I’ve been reading a lot of them recently to catch up on all the new features since I’ve started a new project. BTW they are so much improved and appreciated.

1 Like