> For the complete documentation index, see [llms.txt](https://coldbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox.ortusbooks.com/v4.x-1/digging-deeper/interceptors/interceptor-registration.md).

# 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:

```javascript
// via the controller
controller.getInterceptorService();

// dependency injection
property name="interceptorService" inject="coldbox:interceptorService";
```

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:

```javascript
public any registerInterceptor([any interceptorClass], [any interceptorObject], [any<struct> interceptorProperties='[runtime expression]'], [any customPoints=''], [any interceptorName])

public any registerInterceptionPoint(any interceptorKey, any state, any oInterceptor)
```

**Examples**

```javascript
// register yourself to listen to all events declared
controller.getInterceptorService()
    .registerInterceptor( interceptorObject=this );

// register yourself to listen to all events declared and register new events: onError, onLogin
controller.getInterceptorService()
    .registerInterceptor( interceptorObject=this, customPoints="onError,onLogin" );

// Register yourself to listen to ONLY the afterInstanceAutowire event
controller.getInterceptorService()
    .registerInterceptionPoint( 
        interceptorKey="MyService", 
        state="afterInstanceAutowire", 
        oInterceptor=this
     );
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox.ortusbooks.com/v4.x-1/digging-deeper/interceptors/interceptor-registration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
