> For the complete documentation index, see [llms.txt](https://wirebox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wirebox.ortusbooks.com/aspect-oriented-programming/aop-intro/aspect-binding.md).

# Aspect Binding

Since we have now mapped our aspect in WireBox, we now need to tell it the most important things:

1. To what classes should we apply this aspect to?
2. To what methods or join points should we apply this aspect to?

We do this with another binder DSL method:

* `bindAspect(classes,methods,aspects)`

```javascript
bindAspect(classes=match().mappings('UserService'),methods=match().methods('save'),aspects="MethodLogger");
```

What is up with that funky `match()`.... stuff? Well, the classes and methods arguments of the `bindAspect()` call uses our AOP funky matcher methods that exist in an object called: `wirebox.system.aop.Matcher`. This matcher object is used to match classes and methods to whatever criteria you like. The binder has a convenience method called `match()` that creates a new matcher object for you and returns it so you can configure it for classes and method matching. Here are the most common matching methods below:

| Method                             | Class Matching | Method Matching | Description                                                                                                                            |
| ---------------------------------- | -------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| any()                              | true           | true            | Matches against any class path or method name                                                                                          |
| returns(type)                      | false          | true            | Matches against the return type of methods                                                                                             |
| annotatedWith(annotation,\[value]) | true           | true            | Matches against the finding of an annotation in a cfcomponent or cffuntion or matches against the finding AND value of the annotation. |
| mappings(mappings)                 | true           | false           | Matches to ONLY the named mapping(s) you pass to this method as a list or array.                                                       |
| instanceOf(classPath)              | true           | false           | Matches if the target object is an instance of the classPath. This internally uses the ColdFusion isInstanceOf() method                |
| regex(regex)                       | true           | true            | Matches against a class instantiation path or function name using regular expressions                                                  |
| methods(methods)                   | false          | true            | Matches against a list of explicit method names as a list or array                                                                     |
| andMatch(matcher)                  | true           | true            | Does an AND evaluation with the current matcher and the one you pass in the method.                                                    |
| orMatch(matcher)                   | true           | true            | Does an OR evaluation with the current matcher and the one you pass in the method.                                                     |

WOW! We can really pin point anything in our system! So now that we have binded our aspect to our UserService I can rewrite it to this:

```javascript
component name="UserService"{

    function save(){

      transaction {
         // do some work here
      }

    }
}
```

Now isn't that pretty? Much nicer and compact hugh! Plus I can reuse the method logger for ANY method in ANY class I desire (Muaaaahaaaa), that's an evil laugh by the way! But we are not done, let's keep going and do the Transactional aspect.


---

# 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://wirebox.ortusbooks.com/aspect-oriented-programming/aop-intro/aspect-binding.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.
