Interceptor config

35 views
Skip to first unread message

DK

unread,
Jun 13, 2019, 12:40:08 PM6/13/19
to framework-one
Hi,

if I have the following setup:

Applications.cfc
variables.framework = {
// diEngine = "di1",
diEngine = "aop1",
diLocation = "model",
diConfig = {
interceptors=[
{beanName="authService", interceptorName="authInterceptor", methods="getUser"}
]
}
}

public void function setupApplication(){
// This is working
// getBeanFactory().intercept( "authService", "authInterceptor", "getUser" );

// If I call the intercept below like this I get error that the interceptorName is missing in arguments,
getBeanFactory().intercept();
}
 


model/interceptors/authInterceptor.cfc
component accessors="true" output="false" {

property authService;

function before( targetBean, methodname, args ){
writedump(arguments);abort;
}

}


How do I call multiple interceptor in Application.cfc setupApplication() if I have array of structures declared in the diConfig? 

Thanks
DK

Tony Junkes

unread,
Jun 13, 2019, 7:09:46 PM6/13/19
to framework-one
I’m not sure I completely follow. Can you elaborate a little more? Are you trying to call multiple, different, interceptors. Or trying to call a single interceptor on multiple objects/methods?

In order to accomplish assigning an interceptor to multiple beans/services/controllers/whatever... I’ve had to grab them dynamically, loop over them and call intercept that way within setupApplication.

DK

unread,
Jun 14, 2019, 11:52:55 AM6/14/19
to framework-one
Hi Tony,

I was reading documentation on AOP/1 (http://framework-one.github.io/documentation/4.2/using-aop-one.html)  on how to use/configure the interceptors and it looks like I can define multiple interceptors as an array of structures in the configuration. The idea is to have multiple interceptors for different functionality, initially I would just need authinterceptor.cfc.


Screenshot_20190614_071659.png



So questions are:
1. How do I define multiple interceptors correctly in my example (Should I use diConfig?) 
2. how to call/initiate them (syntax) in the Application.cfc when the application starts? 
Perhaps I'm misunderstanding AOP documentation

thanks 

Tony Junkes

unread,
Jun 14, 2019, 4:59:00 PM6/14/19
to framework-one
Thanks for clarifying.

So for your first question, I think defining multiple interceptors in diConfig is perfectly fine. The only time I've done it by calling getBeanFactory().intercept(...) is for when I have a single interceptor that will be assigned to listen for events from multiple objects and I'd rather set it up dynamically. Calling intercept() is more of a "manual" approach to setting up an interceptor whereas diConfig is more of a one and done approach (unless you override it in setupApplication for example).

Regarding the second question... There shouldn't be a need to "call/initiate" them at this point. Once set in diConfig, the framework handles the rest. So based on your example code, when authService.getUser() is called, the authInterceptor's before() method should fire automatically before the service objects method begins.

Hope that helps.
Message has been deleted

Dejan Karan

unread,
Jun 17, 2019, 9:28:44 AM6/17/19
to framework-one
 Thanks Tony! That helped!
Reply all
Reply to author
Forward
0 new messages