WireBox : Dependency Injection & AOP
7.x
7.x
  • Introduction
    • Contributing Guide
    • Release History
      • What's New With 7.2.0
      • What's New With 7.1.0
      • What's New With 7.0.0
    • Upgrading to WireBox 7
    • About This Book
      • Author
  • Getting Started
    • Overview
    • Installing WireBox
    • Getting Jiggy Wit It!
      • Instance Creations
      • Binder Introduction
      • Scoping
      • Eager Init
      • How WireBox Resolves Dependencies
    • Migrating From ColdSpring
  • Configuration
    • Configuring WireBox
      • Binder Configuration Properties
      • Binder Environment Properties
      • ColdBox Enhanced Binder
      • Types & Scopes
      • Data Configuration Settings
      • Programmatic Configuration
    • Mapping DSL
      • Mapping Initiators
      • Mapping Destinations
      • MapDirectory() Influence & Filters
      • Persistence DSL
      • Dependencies DSL
        • Mapping Extra Attributes
      • Mapping DSL Examples
      • Influence Instances at Runtime
      • Processing Mappings
    • Component Annotations
      • Persistence Annotations
      • CacheBox Annotations
    • Parent Object Definitions
  • Usage
    • WireBox Injector
      • Injector Constructor Arguments
      • Injection Idioms
      • Common Methods
    • Injection DSL
      • ColdBox Namespace
      • CacheBox Namespace
      • EntityService Namespace
      • Executor Namespace
      • Java Namespace
      • LogBox Namespace
      • Models Namespace
      • Provider Namespace
      • WireBox Namespace
    • WireBox Delegators
    • WireBox Event Model
      • WireBox Events
      • WireBox Listeners
        • ColdBox Mode Listener
        • Standalone Mode Listener
  • Advanced Topics
    • Child Injectors
    • Lazy Properties
    • Object Persistence & Thread Safety
    • ORM Entity Injection
    • Providers
      • Custom Providers
      • toProvider() closures
      • Virtual Provider Injection DSL
      • Virtual Provider Mapping
      • Virtual Provider Lookup Methods
      • Provider onMissingMethod Proxy
      • Scope Widening Injection
    • Property Observers
    • Runtime Mixins()
    • WireBox Object Populator
      • populateFromXML
      • populateFromQuery
      • populateFromStruct
      • populateFromQueryWithPrefix
      • populateFromJSON
    • Virtual Inheritance
  • Extending WireBox
    • Custom DSL
      • The DSL Builder Interface
      • Registering a Custom DSL
    • Custom Scopes
      • The Scope Interface
      • Scoping Process
      • Registering a Custom Scope
    • WireBox Injector Interface
  • Aspect Oriented Programming
    • AOP Intro
      • Overview
        • AOP Vocabulary
      • Activate The AOP Listener
      • Create Your Aspect
        • MethodInvocation Useful Methods
        • MethodLogger Aspect
      • Aspect Registration
      • Aspect Binding
      • Auto Aspect Binding
        • ClassMatcher Annotation DSL
        • MethodMatcher Annotation DSL
      • Included Aspects
        • CFTransaction
        • HibernateTransaction
        • MethodLogger
      • Summary
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Aspect Oriented Programming
  2. AOP Intro

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)

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:

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.

PreviousAspect RegistrationNextAuto Aspect Binding

Last updated 2 years ago

Was this helpful?