Hello,
What are the best practices for consuming functions from one module in another in a maintainable manner?
Is using runEvent to call private functions from another module the recommended way to do it?
Thanks
Ivan
Hello,
What are the best practices for consuming functions from one module in another in a maintainable manner?
Is using runEvent to call private functions from another module the recommended way to do it?
Thanks
Ivan
If you want module B to be able to call functions defined in a CFC in module A, why have you made them private? Private functions are not meant to be accessible outside the CFC they are defined in.
private function myPrivateFunction() {
…
}
runEvent() can be use to run ColdBox events in another module, but if your “functions” are more of a utility or a service, I would avoid event handlers and just make them models. For instance, in “moduleA”, put this file:
moduleA//models/myService.cfc
If you are using ColdBox 4, access this model in module B like so:
getModel( “myService@moduleA” ).myFunction()
If you are using ColdBox 3.x, you need to create the “myService@moduleA” mapping in Module A’s ModuleConfig.cfc or just get “myService” and the scan location will find it. The “myService@moduleA” approach is preferred as it namespaces your modules so they won’t conflict.
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com