[coldbox-3.1.0] Apply AOP to handlers

Just wondering if its possible to bind an aspect to a handler in coldbox

Trying to match my handler

bindAspect(
classes=match().to(‘MyHandler’)
,methods=match().methods(‘doSomething’)
,aspects=“MyAspect”);

Doesnt work

However this does work!

bindAspect(
classes=match().any()
,methods=match().methods(‘doSomething’)
,aspects=“MyAspect”);

So it looks like the matcher does search the coldbox Handlers… however when i try to target a specific handler it doesn’t find a match

Thanks guys

You want something like this

binder.mapAspect(“cronusLogger”).to("#moduleMapping#.aspects.cronusLoggingAOP");

or if you wish to annotate the method

binder.bindAspect(classes=binder.match().any(),
methods=binder.match().annotatedWith(“cronusLogger”),
aspects=“cronusLogger”);

or with regEx

binder.bindAspect(classes = binder.match().regex(‘handlers.*’), methods = binder.match().any(), aspects = “cronusLogger”);

To do any matching you need to know the full path name (I think that is how it works), then apply what you want onto that.

Andrew is correct, you have to match the FULL PATH of the handler. My preference, as Andrew also demonstrated, is to do annotation-based matching. To see an example of that, check, out this live runnable example where I’m binding a security AOP advice to actions in a handler.

http://runnable.com/UxAPnxLIPPQRijiK/wirebox-aop-for-security-for-coldbox-coldfusion-cfml-mvc-and-railo

Note: in my example, I used an annotation in the actual aspect to control how it would bind.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks very much!