We have this exact same set of 4 fields (different names, same use)
I used a combination of an 2 interfaces and reflection. All of our BO's inherit from a class that knows how to manage the auditing functionality, but not all the BO's actually have the fields.
The first interface was empty, mainly designed just for testing the derived class to see if it wanted changes audited.
The second interface was optional is just for indicating the values of the field names if they happen to not match the default names, which was true of some of our legacy objects.
So, the common base class can manage updating of the fields when an object is created or changed, even though the properties themselves reside in the low level object.
We did this before CSLA introduced managed properties though. I suspect it would be fairly simple now to just put the properties in the common Base class.
I get the impression that inheritance is something of a can of worms with regards to the static property registration. Seach for "_dummy" for details.
Thanks for the quick replies!!
To subclass would look something like this right (using generics):
public class MyBusinessBase<T> : BusinessBase<MyBusinessBase<T>>
{
private string _whoCreated;
private SmartDate _whenCreated;
private string _whoLastChanged;
private SmartDate _whoLastChanged;
public string WhoCreated{ get; set; }
etc...
}
Cheers,
cdkisa
This is probably better...
public class MyBusinessBase<T> : BusinessBase<T> where T: MyBusinessBase<T>
For example, you want the "Save" method in BusinessBase<T> to return a T, not MyBusinessBase<T>.
And since this declaration constrains T to be a MyBusinessBase<T>, you have the "is a" relationship between your base and derived classes properly established so BusinessBase will accept T as a generic parameter.
Copyright (c) Marimer LLC