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”);
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.
Hand-write out map(“whatIWishItWereCalled”).to(“whatItIsCalled”) for each DAO
Write a cfdirectory and a loop that does the above, but more dynamic
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”
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.