Up Property interceptors
DevForce 2010 Resource Center » DevForce development » Model » Property interceptors » PropertyInterceptor attribute discovery

PropertyInterceptor attribute discovery

Last modified on October 27, 2011 13:02

In general, any interceptor method declared within a DevForce entity and marked with a property interceptor attribute will be automatically discovered before the first property access. PropertyInterceptors will most commonly be defined within the developer-controlled partial class associated with each entity.

Property interceptors can also be defined on any base class and these will also be discovered automatically.

In order to reduce the surface area of any entity class, a developer may not want to expose the property interceptor methods directly on the surface of his or her class. To facilitate this, DevForce will also probe any public inner classes of any entity class and will locate any property interceptors defined there as well.

Example:

C#
/// </summary>
/// <remarks>
/// Property interceptors will also be discovered inside internal class
/// of the Entity class.
/// </remarks>
public class PropertyInterceptorsDefinitions {
  [IbCore.BeforeGet(Employee.EntityPropertyNames.LastName)]
 public static void LastNameInterceptor
    (IbEm.IEntityPropertyInterceptorArgs args) {
   // ...
 }
  [IbCore.AfterSet]
 public static void LoggingInterceptor
    (IbEm.IEntityPropertyInterceptorArgs args) {
   // ...
 }
}
VB
Public Class PropertyInterceptorsDefinitions
  <IbCore.BeforeGet(Employee.EntityPropertyNames.LastName)> _
 Public Shared Sub LastNameInterceptor(ByVal args _
   As IbEm.IEntityPropertyInterceptorArgs)
   ' ...
 End Sub
  <IbCore.AfterSet()> _
 Public Shared Sub LoggingInterceptor(ByVal args _
   As IbEm.IEntityPropertyInterceptorArgs)
   ' ...
 End Sub
End Class

Important note: Property interceptor methods defined on a class directly may be either instance or static methods; whereas property interceptors defined on an inner class (or anywhere other than directly on the entity class) must be static methods.

In the event that a developer wants to completely isolate his interception methods in another non-entity-based class, then discovery will not occur automatically. In this case, the DiscoverInterceptorsFromAttributes  method on the PropertyInterceptorManager class may be used to force discovery of any specified type and all of its base types.

Attribute interceptors that are declared outside of the classes to which they apply must be further qualified via the TargetType property as shown below:

C#
[IbCore.AfterSet(Employee.EntityPropertyNames.LastName,
  TargetType = typeof(Employee))]
public static void LoggingInterceptor(
  IbEm.IEntityPropertyInterceptorArgs args) {
 // ...
}
VB
Public Class UnattachedInterceptor
  <IbCore.AfterSet(Employee.EntityPropertyNames.LastName, _
    TargetType:=GetType(Employee))>
 Public Shared Sub LoggingInterceptor(ByVal args _
   As IbEm.IEntityPropertyInterceptorArgs)
   ' ...
 End Sub
End Class
Created by DevForce on October 07, 2010 14:16

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade