[Coldbox-3.5] Modules Model configuration

I’m looking to create a module that will look for handlers/models/views inside the module first and then the parent if they don’t exist. I have the handlers part working but can’t seem to get the models to look in the module first.

Here is my ModuleConfig:

`

// Module Properties
this.title = “myModule”;
this.version = “1.0”;
this.entryPoint = ‘myModule’;
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = false;

// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = false;

this.autoMapModels = true;

this.parseParentSettings = true;

this.modelNamespace = “myModule”;

function configure() {
interceptorSettings = {
customInterceptionPoints = “”
};
conventions = {
handlersLocation = “handlers”,
viewsLocation = “views”,
modelsLocation = “model”
};

binder.mapDirectory("#moduleMapping#.model");
}

`

In the handler in my module I have a property set:

<cfcomponent> <cfproperty name="myService" inject="model:service.myService" scope="instance"> <cffunction name="myFunction"> <cfset var temp=instance.myService.myServiceFunction()> </cffunction>

And that is calling the model/service/myservice.cfc in parent and not the one I created in module/myModule/model/service/myService.cfc.

What am I doing wrong.

For the view, follow the directory structure described in this page:

https://coldbox.ortusbooks.com/content/full/modules/layout_and_view_renderings/overriding_views.html

For the model, in ModuleConfig.cfc, add this:

// Binder Mappings
// binder.map(“Alias”).to("#moduleMapping#.model.MyService");
binder.map(“MyService”).to("#moduleMapping#.model.MyService");

I hope that helps,

You can’t have automatic overrides of models. WireBox mapping IDs are unique and the last/first one (I think you can choose) to be registered will be used. You can build this behavior though if you want. Manually create a new WireBox instance in your module’s onload and set the “parentInjector” to be the core wirebox instance. Then, instead of using any injection DSL, pass in your custom WireBox injector and if it doesn’t have the model registered, it will ask the parent injector for it. Just like class loaders in Java. Just make sure to change the default application scope registration in WireBox so it doesn’t overwrite the core one.

Thank you for the help on this.

Is there a way that I can send in the name of the module into the injection to specify that I want to use the modules model instead of the parent?

I saw this:
https://coldbox.ortusbooks.com/content/full/modules/model_integration.html

So using my example above, I tried this:

But can’t seem to get it to work. I get a Builder.DSLDependencyNotFoundException.

Not out of the box, but you could always write your own injection namespace DSL. Sound like more work than just swapping your cfproperties with mySpecialWireBox.getInstance().