void set...(...)
is the joinpoint
As you know an Aspect is the association of a Concern, a Pointcut and a Joinpoint
- The implementation of a cross-cutting concern is called the Concern.
- The well defined location within a class where a concern is going to be attached is the Joinpoint.
- The place where the joinpoint(s) are specified, either through configuration or code, is the Pointcut.
A Concern is something that is important to one or more stakeholders. Additionally concerns can conceptually be divided into two categories (the implementation for each can be the same):
A side effect: a concern which is not changing the behaviour at the joinpoint, but instead introduces additional actions.
A logging concern is a good example of a side effect,
e.g. each call to the targeted method (this is the joinpoint) BankWithdrawalHandler.Execute(ICommand command)
will first call the concern LoggingConcern.Execute(ICommand command)
which will be able to run before and after the Execute
method, logging such things as start time/end time/total time/in parameters/out parameters etc.
A side effect can:
- Inspect/capture the input parameters at the targeted pointcut as required and action any additional processing
- Inspect/capture the output result at the targeted pointcut as required and action any additional processing
An advice: a concern which will potentially change the input and/or output of the targeted method.
A caching concern is a simple example - e.g. whenever the run-time executes the targeted method (this is the joinpoint) Repository.Find<T>(long id)
the method CacheConcern.Find<T>(long Id)
will be configured to run first and only allow the call to continue on to the Repository.Find()
method if the value is not found in the cache.
An advice can:
- Inspect the input parameters at a targeted pointcut and modify them if needed
- Cancel or avoid the execution of the targeted method and replace it with a different implementation
- Inspect the output result of the targeted method and modify or replace it as required
Within .NET there are a number of established techniques for implementing the pointcut:
- Post build IL weaving/PostSharp
- Dependency Inversion (Inversion of Control (IoC) and Dependency Inversion (DI))
- Interception/DynamicProxy