You can easily extend the behavior of entities in your model using property interceptors. We'll show you how here.
You'll often want to customize your model with property interceptors to extend the behavior of your entities.
This simple application shows how to declare and work with property interceptors in a Silverlight application. In this sample the two primary ways of creating property interceptors are shown.
In the Customer.cs file, you’ll find several interception methods, all marked with a property interceptor attribute. We’ve only provided a few methods, but this should give you an idea of what you can do:
The DynamicInterceptors.cs file contains several examples showing how to dynamically add interceptors at run time. Interceptors can also be removed and temporarily skipped at run time too, but we don’t show that here.
Two actions are added here, both on Entity. Interception actions on a type apply to that type and all sub-types. Here we provide simple logging on a BeforeSet and AfterSet for any property on any entity.
Unlike the attribute interceptors in the Customer type, which DevForce discovers automatically, we need to specifically add these dynamic interceptors at run time. The AddDynamicEntityInterceptors method is called in Page.xaml.cs when initializing persistence activities.
When you run the application in the Visual Studio debugger (e.g., with F5), you see the results of the interceptors in action.