[Tip of the Week] AOP Simple Interceptions in Handlers

ColdBox handlers all support these simple AOP-style methods that require no configuration to get running:

  • preHandler Executes before any requested action (In the same handler CFC)
  • pre{Action} Executes before the {action} requested ONLY
  • postHandler Executes after any requested action (In the same handler CFC)
  • post{Action} Executes after the {action} requested ONLY
  • aroundHandler Executes around any request action (In the same handler CFC)
  • around{Action} Executes around the {action} requested ONLY

You don’t have to do anything other than define these methods and the ColdBox framework will call them for you. They supply you with a handy method of implementing security, error handling, logging, or whatever else you can dream up to your handlers; even cross-cutting several methods at once!

For more info and some example code, look here: http://wiki.coldbox.org/wiki/EventHandlers.cfm#AOP_Simple_Interceptors

P.S. {Action} would be the name of the action being run. For instance, if your handler had a method (action) called “list”, the convention would be “preList”, “postList”, or “aroundList”.



ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com