RE: [coldbox:16581] Problems with Model and Injections

Yes, to expand on what Luis said, the issue that we can now see in the code you sent is this line:

session.AuthenticationService = new model.AuthenticationService();

Here you are directly creating an instance of the AuthenticationService object. However, if you want to inject dependencies into this object upon creation (in your instance, a data source setting) then you must ask WireBox to create the object for you. WireBox is a DI, or Dependency Injection engine, and follows a principle called IOC, which stands for Inversion Of Control. What that means is you relinquish control over things such as object instantiation, dependency injection, and persistence and let the framework take care of them instead.

So, what does that mean to you? In short, don’t use createObject(), don’t use the “new” keyword, and don’t manually persist objects in the session (or application scope). Instead declare how you want your object to be created and persisted either in your WireBox binder config as:


or declare the component as such:

component singleton {
property name=“something” inject=“DSL”;

component scope=“session” {
property name=“something” inject=“DSL”;

Then, when you want to use that object, you simple ask WireBox for it:

var myModel = getModel(“AuthenticationService”);

WireBox will take care of everything that needs to happen to create that object, inject its dependencies (like your data source) and persist a reference to that object in the scope you specified. (The default scope is “NoScope” which essentially is a transient object)

Hopefully this help clear things up a bit for you.



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

or place this in your handler

property name=“AuthenticationService” inject=“modelAuthenticationService”;

Then you can reference this in your handler like


Should have been

property name=“AuthenticationService” inject=“model:AuthenticationService”;