[wirebox-1.6.0-Standalone] Multiple Instances of a CFC?

I have one blog CFC that returns blog results based on the params of the init(). I need to read that into two variables.

// Old Way…
application.BlogMain = createObject(‘component’,‘object.Blog’).init(“http://news.mySite.com/feed/?cat=2”);
application.BlogEvents = createObject(‘component’,‘object.Blog’).init(“http://news.mySite.com/feed/?cat=4”);

We moved the methods over to a new CFC to bring them into Wirebox.

// Attempt in Wirebox…
application.BlogService = application.wirebox.getInstance(‘BlogService’).init(“http://news.mySite.com/feed/?cat=2”);
application.BlogServiceEvents = application.wirebox.getInstance(‘BlogService’).init(“http://news.mySite.com/feed/?cat=4”);

The problem with this is that the second call runs the init and it changes the object at a deep enough level so that the “blogService” object (the first one) is changed as well.

After some research, I created an alias in a Binder, and got it to work. But it seemed like it was overly complicated. Is there a better/simpler way… like one that doesn’t have to use a binder config file? I would think this would be a pretty common task.

thanks for any help!

(based on a doc I found, I think my WB version is 1.6. I don’t know how to find out programmatically.)

Hi David,

First of all, when using WireBox, you don’t have to use init() anymore. Basically, you are calling it twice. The purpose of WireBox is to create and initialize the objects for you. So you don’t need to do that anymore.

As for your init arguments, you will need to either map them in your binder like:

map( “BlogMain” )
.to( path )
.initArg( value=“http://news.mySite.com/feed/?cat=2” )
.into( “application” );

map( “BlogServiceEvents” )
.to( path )
.initArg( value="http://news.mySite.com/feed/?cat=4” )
.into( “application” );

Or you can pass an optional struct to “getInstance” called initArguments

getInstance( name=“BlogService”, initArguments={ name=“path” } );

Also, it seems that you need to map two instances of the same CFC with different parameters, so you cannot call them or alias them the same. Look at my mapping above. Also, you do not need to set them in application scope also. You can let wirebox binding do it for you.

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano