[ColdBox 4.1.0] Use module binder mapping in another module

Is it possible to use a mapping from one module in another?

Ex:
Module1 has a model called userModel.cfc

There is a binder: binder.map(“theUserModel”).to("#moduleMapping#.models.userModel");

In Module2 I need to use that model from Module1 but it seems like does not work.

Do I need to just create a binder in Module2 like: binder.map(“theUserModel”).to(“Module1.models.userModel”); or is there another way to inject it?

Yes, modules can use any mapping from another module. What is probably happening is your modules are loading in the wrong order. use this.dependencies in your modules to specify what other modules need to load first.

I would recommend not bothering to manually map your models. As of ColdBox 4, everything in your modules’ models folder gets automapped with the mapping namespace you configure in ModuleConfig.cfc (defaults to module name)

So in your example, module2 just needs to specify module1 as a dependency and inject “usermodel@module1”. if you want to call it something different, you can also add an alias annotation to the CFC.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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