[Coldbox 4.3.0] CF2016 - How to inject a business component in a service?

I created a few utility components such as randomString, randomPassword etc… which I placed under /includes/helpers/utils directory. I wanted to call the randomString component in a service called UserSVC by injection, like so:

// Dependency Injection

property name=“dao” inject=“models.rrm.UserDAO”;
property name=“gw” inject=“models.rrm.UsersGW”;

property name=“rString” inject=“includes.helpers.utils.RandomString”;

property name=“log” inject=“logbox:logger:{this}”;
property name=“populator” inject=“wirebox:populator”;
property name=“wirebox” inject=“wirebox”;

function init(){
return this;

}

with the method in the UserSVC component like this:

// Return a random string as the default user account screen name

public string function randomString(required numeric length) {

return rString.RandomString(arguments.length);

}

But I get an error message: method randomString is undefined in UserSVC.

Question: Should all invoked business components be considered part of the model and therefore be located under the “models” directory instead of any other directory such as “includes” for them to be recognised by ColdBox? Or should I create a mapping in Wirebox?

If I were you, I would wrap the utility components in a ColdBox module. See this ForgeBox: BCrypt or ForgeBox: CB Commons as an example.

I have moved all the utilities under the models directory and it works now. As for wrapping the utility components in a Coldbox module, I think it is a great suggestion. I am going to try it now. Thanks.