When using DynamicProxy, avoid creating monolithic interceptor classes that handle multiple concerns (e.g., combining logging, security, and parameter verification). Instead, leverage the ability to apply multiple interceptors to a single method call.
Recommended patterns for interceptor design:
- General Purpose Interceptors: Create interceptors that perform a single task (like logging) and apply them globally to all intercepted methods.
- Class-Specific Interceptors: Create interceptors for specific hierarchies (e.g., classes inheriting from a common base) that focus on one responsibility.
- Method-Specific Interceptors: Create interceptors that target a single method on a specific class or interface.
Use interceptor selectors to match these specialized interceptors to their intended targets, ensuring each interceptor remains focused on a single responsibility.