Auditing and collections

Posts   
 
    
Leo
User
Posts: 4
Joined: 30-Oct-2007
# Posted on: 04-Nov-2008 22:12:29   

My auditor class currently takes in user info and audit configuration in the constructor. So, I've been setting the AuditorToUse property manually (no DI).

I need to audit loading of entities in to a collection. Is there a way to do that and keep the ability to provide user info and config to the auditor?

Thanks!

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Nov-2008 23:16:01   

When you say "loading of entities into a collection" do you mean fetching an entity collection (using .GetMulti or .FetchEntityCollection) or adding existing, already fetched entities into a collection ?

If the former you can override AuditLoadOfEntity in your validator class, which will be called for each entity fetched from the database. Because this is on your existing validator the information passed into the constructor will still be available to you.

I'm not sure if there is an easy way to distininguish between fetching an entity as part of a collection and a fetching a single entity though...

Matt

Leo
User
Posts: 4
Joined: 30-Oct-2007
# Posted on: 05-Nov-2008 00:57:48   

Thanks for the response. I was referring to fetching an entity collection. I already have an overridden AuditLoadOfEntity method in my auditor. The problem is when fetching an entity collection, how to assign my auditor to each entity.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Nov-2008 05:17:15   

You could opt for overriding **OnInitializing **in an entity to add the creation of the Auditor class. This way, the auditor is always set, no matter whether or not it belongs to an entity collection.

Though I don't know how are you passing the configuration and user info to the constructor (where do you obtain that info). In our Auditor example, we use a separate assembly that gets the user info, we do this inside the constructor (parameterless).

David Elizondo | LLBLGen Support Team