Context Standard Plugin: Simple AOP

The SimpleAOPPlugin is a standard plugin that can be implemented easily with either a regular PluggableContext or an HTTPContext. This is another plugin that evolved from the Quicksilver framework that leverages the org.cfcommons.aop module library to provide a very simple, named-based join-point model to quickly and effectively employ aspect oriented programming techniques within your context functionality.

Name-Based Join-Point Model

Flagging and applying cross-cutting concerns is as easy as giving your aspects names. Naming an aspect is as simple as annotating a CFC method with the cfcommons:aop:advice:name annotation like so;

In the example above, we flagged the doSomething() method as a reusable aspect with a name of myAspect.

Creating Join-Points

Now that you have a context CFC that has a named aspect, you can now easily apply that aspect to any number of other context CFC methods by simply referencing the name of that aspect in your join point. The SimpleAOPPlugin supports the application of aspects at the three supported join-points of the native org.cfcommons.aop library; before, after and around. To apply an aspect at a specific join-point, all you need to do is utilize the corresponding annotations;

@cfcommons:aop:before:advice
@cfcommons:aop:after:advice
@cfcommons:aop:around:advice

Both the before and after annotations will accept a comma-delimited list of valid aspect names and each aspect will be applied to the corresponding method in the order in which they were declared. Technically speaking, there's no limit to the number of aspects that can be applied to a point-cut method;

Because the org.cfcommons.aop library is powering our AOP implementation for this plugin under the hood, the around advice must adhere to the general contract of around advice set-forth by that library. The gist of it is that a point-cut can have only one aspect applied of type around. This is because AOP delegates the execution of the underlying point-cut to the aspect - meaning, it's the responsibility of the around aspect to invoke the original point-cut method in it's implementation. If at any point you attempt to apply more than one around aspect to a point-cut method, an exception will be thrown indicating that this is not allowed.

Ask for your instance through the Context API

Now whenever you ask for an instance of your CFC through the Context API's getObjectInstance() method, the resulting object will have all aspects properly applied to the point-cut methods that you've defined.

Quick Nav

All Modules

In Touch

Featured Module

Contribute

Download Now