Coldbox [4.0.0] - Handler and DI and calling a method?


I’m trying to setup a property in my handler and wanted to know if there is a way to do something like (psuedo code below)

Basically I wanted to inject my Stripe Service into my handler, but call the init() method and pass a coldbox setting as a param…

Can something like this be done in one shot?


Usually, you don’t do that as it couples the construction of the object.

You would just inject an instance of the stripe service:

property name=“stripe” inject=“Stripe”;

You can configure the Stripe service either by annotations or in your configuration Binder to set the constructor argument like:

map( “Stripe” ).to( “models.Stripe” ).initArg( value=getProperty( “stripeTestKey” ) );

Luis Majano
Ortus Solutions, Corp
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform:

ContentBox Platform:
Linked In:

Social: | | |

Ahh… sweet, that makes sense. Thanks for pointing me down the right path.

You are trying to mix concerns. The handler code should need to know or care about the stripe object’s dependencies. The handler should simply ask WireBox to inject stripe and that’s it-- let stripe handle its own dependencies.

You may noticed I omitted the “model:” part too as that is the default injection DSL namespace.

So, the easiest thing to do in my opinion is add this to your stripe.cfc:

This will tell WireBox that any time it creates a Stripe instance, to inject the setting. There is no limit to the depth of the potential dependency tree.

Note, “variables.testKey” won’t be available in your init, but it will be available in your onDIComplete() method. If you insist on using constructor injection, then add this to your Stripe’s init() method:

WireBox will automatically pass the testKey into you rinit for you.



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

What you’ve laid out Brad makes sense and thank you for taking the time to respond to my post.

I will just inject the stripe key using cfproperty versus in the constructor as an argument as you mentioned.