Managing Module Dependencies in External Locations

I am building a new module within my project’s modules_apps directory. The new module depends on a module located in an external directory. When I reference the module located in the external location from my new module, it doesn’t exist. I presume this is because modules in the module_apps directory load before externally located modules.

I can call the external module from a handler within the project, but I can’t call it inside the module located in the module_apps directory.

The external module is defined as a dependency inside ModuleConfig.cfc. The external module’s location is also in the project’s Coldbox.cfc file. Is there a way to ensure the external modules load before the project’s module_apps directory loads?

Hi Matthew,

I tried setting up the scenario you’ve outlined and it worked for me. However, there might be a couple “gotchas” that might be causing your problem. I don’t think we’ve met and I don’t know your level of Coldbox experience so if some of these are basic issues, I apologize.

Here is the folder structure I tried with:

  • myRemoteModuleParent (C:\sites\experiments\remotemod)
    • myRemoteModule
      • config
      • handlers
      • models
        • remMod.cfc
      • views
  • myColdboxRoot (C:\sites\experiments\moduleorder)
    • modules_app
      • myNewModuleWhichReferencesMyRemoteModule
        • config
        • handlers
          • Home.cfc
        • models
        • views
          • home
            • index.cfm

The external module is “myRemoteModule” (just in case that wasn’t clear) and I’m developing the myNewModuleWhichReferencesMyRemoteModule in my Coldbox app. My remote module (remMod.cfc) was a simple:

component {
function runMe(){
writeDump(“This is run me”)
}
}

  1. Make a CFMapping to the myRemoteModuleParent. When Coldbox is scanning for modules, it doesn’t scan the folder it’s pointed to, it scans the folders IN that one and looks for a ModuleConfig.cfc. If you’re using cfconfig, here is the CFMappings node I used:

“CFMappings”:{
“/rem”:{
“PHYSICAL”:“C:\sites\experiments\remotemod”
}
},

  1. In the config/Coldbox.cfc, put the virtual part of the mapped drive in the modulesExternalLocation, array like this:

modulesExternalLocation : [“/rem”],

  1. You can make sure that the module loads either by watching the logs ( server log --follow if you’re using CommandBox) or the Coldbox default page.
    image

  2. Other than that, I was able to reference the remote module from within my local handler, Home.cfc

component{
property name=“rem” inject=“remMod@remoteMod”;

function index( event, rc, prc ){
prc.remMod=rem;
event.setView( “home/index” );
}
}

  1. and then display it in my view:

<cfset prc.remMod.runme() />
< h1 >Welcome to my cool module page!

Hope this helps!

Thank you, Dan,
I reproduced your example, and as you explained, the process works when calling a method from an external module inside a handler. It also works within my project.

However, in my project, I am encountering a different scenario. I am calling a method from an object in the project’s module. Making the call inside the object works in your example but fails in my project.

Therefore, as you pointed out, something else is preventing the module from loading. I am unsure what it is right now, but I appreciate that you responded and gave me some steps to consider for my project. I am still using ColdBox 6.9.0.

As a workaround, I am calling Wirebox from the application scope. application.wirebox.getInstance(‘remMod@remoteMod’). It’s not ideal, but it is the only way I can get it to work for now.

I don’t know whether we met. Many years ago, I was a member of TACFUG, helping to plan the first couple of NCDevCons. I also spoke at the first conference when my former boss, Brian Kotek, couldn’t attend. I haven’t attended any CF conferences since, but my coworkers attend.