# 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 or CFCs 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 CFC 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wirebox.ortusbooks.com/aspect-oriented-programming/aop-intro/aspect-binding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
