ColdBox Mode Listener

ColdBox Interceptors

In ColdBox, you will create ColdBox Interceptors to listen to any event in the application. Each of these methods that listen to events receive the following arguments:

Argument

Type

Description

event

RequestContext

The request context of the running request

data

struct

The data structure passed in the event

buffer

RequestBuffer

A request buffer object for producing elegant content in ColdBox applications

rc

struct

Reference to the rc scope

prc

struct

Reference to the prc scope

Example

So, let's say we want to listen to the beforeInjectorShutdown and the afterInstanceCreation event in our listener.

component{

    function configure(){}

    function beforeInjectorShutdown(event, data, buffer, rc, prc ){
        var injector = arguments.data.injector;
        // Do my stuff here:

        // I can use a log object because ColdBox is cool and injects one for me already.
        log.info("DUDE, I am going down!!!");
    }

    function afterInstanceCreation(event, data, buffer, rc, prc ){
        var injector = arguments.data.injector;
        var target = arguments.data.target;
        var mapping = arguments.data.mapping;

        log.info("The object #mapping.getName()# has just been built, performing my awesome AOP processing on it.");

        // process awesome AOP on this target
        processAwesomeAOP( target );
    }
}

Last updated