Wirebox 2.0 and automagically mapping with aliases

I’m working on a project for a client where they are evaluating DI engines. Their naming convention for the DAOs is inconsistent with the names of constructor args that reference them.

As a result, I’d like to create custom aliases for CFCs in a specific directory. I assume I can read the directly myself and build the mappings dynamically in the binder, but I just thought I’d check here first to see if there is some hidden gem that does this for me.

To be more clear about what I’m doing… I have a directory with more than a couple dozen CFCs that are named without a “DAO” suffix (“users”) but each of the model objects that have dependencies on these files expect them to have the “DAO” suffix (“usersDAO”);

Here’s a few of options:

  1. Add an alias=“whatIWishItWereCalled” in the component declaration and just mapDirectory(). Note this will create BOTH mappings, so this won’t work if you have multiple CFCs in different directories with the same name.
  2. Hand-write out map(“whatIWishItWereCalled”).to(“whatItIsCalled”) for each DAO
  3. Write a cfdirectory and a loop that does the above, but more dynamic
  4. Map the directory with a namespace (like how ColdBox modules work)
    mapDirectory( packagePath="/model/dao", namespace="@DAO" )
    Each mapping would come out as “whatItIsCalled@DAO”
  5. And finally, this is a crazy one-- but just RENAME the files! Believe it or not, this option is probably less overall time and it’s way cleaner than anything else. And when using a DI engine like WireBox property, you can move models without the application code even needing touched-- since the mapping name can stay the same. Worst case scenario, is a quick global find and replace.



ColdBox Platform Evangelist
Ortus Solutions, Corp

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

I opted for #3. It was roughly 4 extra lines of code to read the directory and call map() for each DAO.

Renaming the files simply wasn’t an option as we’re evaluating DI solutions now. Thanks for the thoughtful reply.