I want to be able audit user actions on the domain model - I want to track when & what they've changed. Now I can do this at the course grained level using nHibernate event listeners, they can tell me when an entity is loaded, saved, updated etc. But without interrogating the state of the entity in depth I'm unable to determine what's gone on between loading an entity and it being saved.
This is where the idea of domain events comes the rescue - the idea of generating events from the domain model. Now this could be done using the standard .Net event pattern, but as described in the above link the use of a decoupled domain events is way more powerful -the use of an intermediary ('DomainEvents' class) to decouple the domain model from the event handlers is simplistic and beautiful.
So now I can have an auditing service listening to both nHibernate & the domain model to track user actions across the domain and when a domain entity is persisted I can then push out the audit data to a message queue for processing asynchronously.
My requirement for auditing goes further than just tracking what a user did, it also includes tracking usage (of the domain model) - we want to track every time a user accesses content to provide usage reports and invoice accordingly...
This will be collected via the same domain events - it's just another specific audit handler, etc.
Simple!
Awkward Coder
This is where the idea of domain events comes the rescue - the idea of generating events from the domain model. Now this could be done using the standard .Net event pattern, but as described in the above link the use of a decoupled domain events is way more powerful -the use of an intermediary ('DomainEvents' class) to decouple the domain model from the event handlers is simplistic and beautiful.
So now I can have an auditing service listening to both nHibernate & the domain model to track user actions across the domain and when a domain entity is persisted I can then push out the audit data to a message queue for processing asynchronously.
My requirement for auditing goes further than just tracking what a user did, it also includes tracking usage (of the domain model) - we want to track every time a user accesses content to provide usage reports and invoice accordingly...
This will be collected via the same domain events - it's just another specific audit handler, etc.
Simple!
Awkward Coder
Comments
Post a Comment