I am re-architecting my development around custom modules. What I am doing is to relocate model components, handlers and views that share the same admin purpose under a specific module called “administration”. I updated all prior model mappings in wirebox like so:
When I run the event on the handler located at: modules_app/administration/handlers/crd/Carriers.cfc, I get the error attached below. How should I understand this error?
1 - Is it a mapping issue involving the component carrierSVC.cfc and the injection properties?
2 - my new handler “administration/crd/carriers” does not seem to be registered, how do I register it? Should I add new routes in the moduleConfig file?
3 - Both of the above?
Yes, to confirm what Sana said, I would recommend not mapping you rmodels at all-- modules automatically map you rmodels for you! Just make sure that **this.**autoMapModels setting is on in your ModuleConfig.cfc.
On the topic of mapping, there’s a couple of problems with the above code. The first is that you appear to be mapping the models from a module in your core Wirebox config. Don’t do this-- the goal of a module is to be self contained. If you do want to map a model that belongs to a module, do so in the ModuleConfig.cfc for that module. just prepend your mapping DSL with “binder.”
binder.map( ‘foo’ ).to( ‘bar’ )
Secondly, don’t make assumptions about where your module is installed to. You have the path “modules_app” hard coded in there, but what if you move this module to an external location or the modules folder? Instead, use the “moduleMapping” variable that is available to you in your ModuleConfig.cfc which is dynamically created for you by the framework and contains the CFC path to the root of the module. So it would be something like:
Now your mappings are fully contained within the module and are insulated against future refactoring. Of course, I recommended you not map at all, but if you do keep this in mind
And finally…
Your error message shows that WireBox is looking for the injection DSL: “id:crd.CarrierSVC”. You can omit the “id:” portion entirely of the mapping DSL, that’s just noise. The mapping ID “crd.CarrierSVC” doesn’t exist because you mapped it as " CarrierSVC". Turn on auto model mapping like Sana suggested and then inject it as :
Brad, thank you! In fact, “this.autoMapModels” setting appears to be set to true by default in the moduleConfig file. I was not aware that “binder” could make DSL mappings much neater and self contained within the module. Thanks again for this tip.
However, I now get a more serious error like the one attached below. If I keep mappings in Wirebox it still works, but I had rather only work with ModuleConfig only. Any further suggestions?
You need to wrap the name in quotes. The way you’ve typed this is looking for a variable called “Carrier”.
Also, may I ask again why you are mapping these at all? I would recommend you use the default mappings provided to you out of the box. It’s less work and helps reduce ambiguity. Note the mapping namespace is configurable. So if you don’t like “Carrier@administrator” you can do “Carrier@admin”, etc.