RE: [coldbox:11248] WireBox - Map and MapPath are they the same?

They are not the same.

“map” in used to create a single mapping in the injector between an ID of your choosing (the parameter to the map() function) and a single object (which you define in the chained to() function call. map().to() can also be followed by additional chained modifiers such as inScope() or asSingleton().

“mapPath” accepts a directory and recursivley looks for all CFCs in that directory and maps them all to a default ID of their name. mapDirectory looks at the metadata in the CFC for any additional modifiers (such as scope=“session” or singleton=“true”), but you cannot chain the call in the config.

I have a small handful of providers that I map specifically in my WireBox config. Other than those, I am lazy and I use mapDirectory to keep myself from actually have to map all my other CFC’s by hand. I just throw it at my models directory and it creates hundreds of mappings for me.

Does that clarify?



Actually, Brad, that’s not accurate.

mapDirectory() is the one that recurses.

mapPath() basically is the same as map() but without adding the alias it assumes the alias off the CFC filename


Is essentialy the same. The map() method gives the flexibility of adding more than 1 aliased key, but also to attach it to any TO destination. mapPath() is a shorthand notation for CFC’s.

Luis F. Majano
Ortus Solutions, Corp

ColdBox Platform:
Linked In:
IECFUG Manager: