[coldbox-5.2.0+791] extend model to get access to getInstance

In a model, I need access to getInstance() so that I can call getInstance( “BCrypt@BCrypt” ). What does my model need to extend in order to be able to call getInstance()?

Right now, I’m getting:

No matching function [GETINSTANCE] found.

You need to inject wirebox into your model and then you can call wirebox.getinstance(). But why aren’t you just injecting BCrypt into your model directly? So long as you’re not injecting a transient into a singleton, that seems like the best approach.

component {
property name='BCrypt" inject=“BCrypt@BCrypt”;

function someMethod() {
BCrypt.foo();
}

}

You need to inject wirebox into your model and then you can call wirebox.getinstance().

Sorry but how do I do that?

But why aren’t you just injecting BCrypt into your model directly?

When I try that, I’m getting:

The target ‘MyModel’ requested a missing dependency with a Name of ‘BCrypt’ and DSL of ‘BCrypt@BCrypt’

Sorry but how do I do that?

component {
property name='wirebox" inject=“wirebox”;

function someMethod() {
var BCrypt = wirebox.getInstance( ‘BCrypt@BCrypt’ );
BCrypt.foo();
}

}

When I try that, I’m getting: The target ‘MyModel’ requested a missing dependency with a Name of ‘BCrypt’ and DSL of ‘BCrypt@BCrypt’

It depends on what model you’re trying to inject it into and when that model is being created in the app lifecyle. It’s possible your model is being created before the modules have been loaded. I’d need to see a stack trace to know for sure. Adding “provider:” to the start of the injection DSL will likely fix it.

property name='BCrypt" inject=“provider:BCrypt@BCrypt”;

Adding “provider:” to the start of the injection DSL will likely fix it.

That worked. Again.

Thanks, Brad!