[ColdBox 4.3.0] Modeling a collection of objects

23 views
Skip to first unread message

Dave Merrill

unread,
Sep 19, 2017, 7:52:39 AM9/19/17
to ColdBox Platform
Long-time CF guy but ColdBox newb here, aware of it forever, haven't really used it.

I'm thinking about a model to represent cumulative stats on a collection of objects, each of whose data is a json file in the file system. That strikes me as two model objects, one for an individual object and one for the collection.

Outside of ColdBox, I'd create an instance of the collection object, which would get a list of all the applicable files, and for each one, call new Item(filePath), ask it for its individual info, and accumulate the collection stats.

Is there a ColdBox-style equivalent to those new Item(filePath) calls? AFAIK, there's no way to represent creating multiple instances of a transient (non-singleton) model object.

Is there some concept or syntax I'm unaware of, or should I just go with native new Item() calls?

Thanks.

Luis Majano

unread,
Sep 19, 2017, 3:57:32 PM9/19/17
to ColdBox Platform
Welcome aboard Dave!!

The concept you are talking about is an object model concern and not a ColdBox concern.  Thus, you would use WireBox to create the objects for you to provide you with consistency, dependency injection and state.  So just leverage WireBox to create the objects for you.

wirebox.getInstance( “path or alias” );


Luis Majano
CEO
Ortus Solutions, Corp

Dave Merrill

unread,
Sep 19, 2017, 10:32:41 PM9/19/17
to ColdBox Platform
Thanks for jumping in Louis.

I thought WireBox was for dependency injection, and I didn't see a way to "inject" multiple new transients. I hadn't thought about asking the DI provider for them, sounds reasonable.

Dave
Reply all
Reply to author
Forward
0 new messages