RE: [coldbox:18177] [coldbox 3.6.0] Question on Wirebox (getModel and getInstance)

You generally don’t need to inject Wirebox into any ColdBox component such as a handler, view, interceptor, or plugin. They all have the getModel() available to you to use.

However, your model objects don’t inherit from the frameworkSuperType (unless you make them), so you’ll need to inject in the things you want to have access to. Singletons (or objects with a longer-lasting scope than the receiving object) can be injected directly. Transients (or shorter-scoped objects in sessions, request, etc) need to be requested from WireBox every time. In those instances, it is normal to inject WireBox itself and ask it for whatever you need.

// This works

var SD = wirebox.getInstance(“OBJ.SOMEDATAOBJ”);

Yep, nothing wrong with that code.

// These methods do not work
// var SD = getModel(“OBJ.SOMEDATAOBJ”);

That’s because your models don’t have the “magic” ColdBox methods like getModel() that handlers and views have.

// var SD = wirebox.getModel(“OBJ.SOMEDATAOBJ”);

The actual method in Wirebox is called getInstance(). The getModel() method is a throwback to our now-deprecated bean factory plugin and I think we left it in the handlers, views, etc for backwards compat. If you open up the frameworkSuperType CFC, you’ll see getModel simply turns around and calls controller.getWireBox().getInstance(argumentCollection=arguments).

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Thank You, I feel better now about using it. Does that mean populateModel and validateModel are depreciated as well or were they moved into Wirebox?