Interceptor Registration
You can also register CFCs as interceptors programmatically by talking to the application's Interceptor Service that lives inside the main ColdBox controller. You can access this service like so:
1
// via the controller
2
controller.getInterceptorService();
3
4
// dependency injection
5
property name="interceptorService" inject="coldbox:interceptorService";
Copied!
Once you have a handle on the interceptor service you can use the following methods to register interceptors:
    registerInterceptor() - Register an instance or CFC path and discover all events it listens to by conventions
    registerInterceptionPoint() - Register an instance in a specific event only
Here are the method signatures:
1
public any registerInterceptor([any interceptorClass], [any interceptorObject], [any<struct> interceptorProperties='[runtime expression]'], [any customPoints=''], [any interceptorName])
2
3
public any registerInterceptionPoint(any interceptorKey, any state, any oInterceptor)
Copied!
Examples
1
// register yourself to listen to all events declared
2
controller.getInterceptorService()
3
.registerInterceptor( interceptorObject=this );
4
5
// register yourself to listen to all events declared and register new events: onError, onLogin
6
controller.getInterceptorService()
7
.registerInterceptor( interceptorObject=this, customPoints="onError,onLogin" );
8
9
// Register yourself to listen to the onException event ONLY
10
controller.getInterceptorService()
11
.registerInterceptionPoint(
12
interceptorKey="MyService",
13
state="onException",
14
oInterceptor=this
15
);
Copied!
Last modified 2yr ago
Copy link