[ColdBox 4.0] Injecting a service into interceptor

I’m trying to inject my security service into an interceptor:

`

component extends=“coldbox.system.Interceptor” {

// DI
property name=“securityService” inject=“SecurityService@area51”;

public void function preProcess( event, interceptData ){

var rc = event.getCollection(private = false);
}
}

`

But I got this error:

The DSL Definition {REF={null}, REQUIRED={true}, ARGNAME={}, DSL={id:cookieStorage@cbstorages}, JAVACAST={null}, NAME={cookieStorage}, TYPE={any}, VALUE={null}, SCOPE={variables}} did not produce any resulting dependency
Detail The target requesting the dependency is: ‘SecurityService@area51’
Stacktrace The Error Occurred in
E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Builder.cfc: line 380

378: throw(message=“The DSL Definition #arguments.definition.toString()# did not produce any resulting dependency”,
379: detail=“The target requesting the dependency is: ‘#arguments.targetID#’”,
380: type=“Builder.DSLDependencyNotFoundException”);
381: }
382: // else return void, no dependency found that was required

called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 603
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 490
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\scopes\Singleton.cfc: line 57
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 261
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Builder.cfc: line 471
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Builder.cfc: line 362
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 603
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 490
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\scopes\Singleton.cfc: line 57
called from E:\wamp\www\TropicalSeo\app\coldbox\system\ioc\Injector.cfc: line 261
called from E:\wamp\www\TropicalSeo\app\coldbox\system\web\services\InterceptorService.cfc: line 254
called from E:\wamp\www\TropicalSeo\app\coldbox\system\web\services\InterceptorService.cfc: line 195
called from E:\wamp\www\TropicalSeo\app\coldbox\system\web\services\InterceptorService.cfc: line 107
called from E:\wamp\www\TropicalSeo\app\coldbox\system\web\services\InterceptorService.cfc: line 75
called from E:\wamp\www\TropicalSeo\app\coldbox\system\web\services\LoaderService.cfc: line 53
called from E:\wamp\www\TropicalSeo\app\coldbox\system\Bootstrap.cfc: line 71
called from E:\wamp\www\TropicalSeo\app\coldbox\system\Bootstrap.cfc: line 107
called from E:\wamp\www\TropicalSeo\app\coldbox\system\Bootstrap.cfc: line 350
called from E:\wamp\www\TropicalSeo\app\Application.cfc: line 57

So how can I access my security service into interceptor?

Interceptors are created before modules are loaded so at the time your interceptor gets created, that model mapping doesn’t exist yet. You can work around this by injecting a provider which will delay creating of the dependency.

property name=“securityService” inject=“provider:SecurityService@area51”;

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 Brad,

I’m testing with:

`
Wirebox.getInstance(“SecurityService@area51”)

`

It’s the same? Which one should I prefer?

As long as you don’t call that in your interceptors constructor, that will work too providing the interception point is one that fires after the modules have been loaded.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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