Generic Before / After Save hook?

Jul 4, 2011 at 8:39 PM

I know there are Before and AfterSave hooks in defined triggers for specific types, but what I'm looking for is a single hook that I can
call a method on my base class with.

Background: The Base class implements IChangeTracking from System.ComponentModel, and I'd like to call ApplyChanges before/after the save of the object is made.

Is there a way to do this - or a recommended pattern?

Currently, the only other alternative that I can see is using the OperationOccured event on the database, and then somehow using the Load method with
the event args to load the saved object and call ApplyChanges on it - but this seems like a bit of overkill.

Jul 5, 2011 at 11:49 AM

What's wrong with doing a generic trigger processor that calls through? This is similar to the pattern of auto-incrementing an integer. Use a common base class for the key and then use the trigger to call with <T> where t: Base and then just call the base method. Should work the same for what you are doing. Click on the documentation tab and look at the MSDN article for an example of how that works.

Jul 5, 2011 at 5:58 PM

This was the first thing I tried - although I was looking for a single line of code to tell Sterling to apply the trigger to all types that inherit from T (the base class).

As it stands, if I understand it correctly, I can define a generic trigger, but I still need to register that trigger for every type in my domain model.

Jul 5, 2011 at 6:26 PM

In the same vain - it would have been nice to tell Sterling that any tables that inherit from type T what the DirtyFlag is, instead of having to specify the same dirtyflag for every RegisterTable.

Jul 5, 2011 at 6:31 PM

That sounds like a great suggestion - please consider adding it in the Issue Tracker tab where people can vote on it to go into a future release.